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
https://forums.phpfreaks.com/topic/236300-indexphppage1-pulling-data-from-db/
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'];
}
?>

Why are you selecting everything from the database?

 

 

$page = (int)$_GET['page'];
$sql = mysql_query("select * from page where page_id = $page");
if(mysql_num_rows($sql)>0){
    $row = mysql_fetch_assoc($sql);

    echo $row['text'];
}else{
    // No rows were returned
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.