Jump to content

index.php?page=1 pulling data from DB


whare

Recommended Posts

index.php?page=1 that link style but there is not hard files it is all to be stored in the DB

 

here is what i have got so far

 

<?

$result = mysql_query("SELECT * FROM page") or die(mysql_error());
$row = mysql_fetch_array( $result );

if(isset($_GET['page'])) {
echo $row['text'];
} else {
$result = mysql_query("SELECT * FROM page
WHERE id='1'") or die(mysql_error());
$row = mysql_fetch_array( $result );
echo $row['text'];
}
?>

 

but always shows page ID 1 (home page) so i no i am missing something just not sure what hehe

 

DB structure:

menu
----id (auto increase)
----name (home, about etc)
----id2 (page weight)
pages
----id (auto increase)
----name (page name home, about etc)
----text (page text)

 

link structure from the menu

 

<?

$result = mysql_query("SELECT * FROM menu ORDER BY id2") or die(mysql_error());  


?>
<table>
<?
while($row = mysql_fetch_array( $result )) { ?>

<tr><td> 
<a href="index.php?page=<? echo $row['id'];?>"><? echo $row['name']; ?></a>
</td></tr> <?
} 
?>
</table>

 

 

dont think i have missed any info that i have on file but not sure why it will not link so thought of you guys hehe

 

Thanx in advance

:)

Link to comment
Share on other sites

<?
if(isset($_GET['page']) && is_numeric($_GET['page'])) {
$result = mysql_query("SELECT * FROM page WHERE id='" . $_GET['page'] . "'") or die(mysql_error());
$row = mysql_fetch_array( $result );
echo $row['text'];
} else {
$result = mysql_query("SELECT * FROM page
WHERE id='1'") or die(mysql_error());
$row = mysql_fetch_array( $result );
echo $row['text'];
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.