Problem extracting data from MySQL to use in metadata

I have (following various tutorials) made a simple page (or two) that writes to the database, reads from the database and gives it a link such as page.php?id=1, using the ID in the database.
The problem is, filling metadata tags doesn’t happen. I tried placing the PHP above the metadata tags (not sure if that helps?) but it still doesn’t seem to get the data in time.

Here is my code:
Any tips to improve it in other ways as well are always appreciated

[php]

<?php $username="dbuser"; $password="dbpass"; $database="dbname"; $table="data"; $localhost="localhost"; $_SERVER['QUERY_STRING']; mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM $table WHERE id='$_GET[id]'"; $id="$_GET[id]"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $text=mysql_result($result,$i,"text"); echo "ID: $id
Link: $text

"; $i++; } mysql_close(); ?> <?php $text ?> <?php echo "Database Output

";

?>

[/php]

As you can see I tried inserting the text variable as the title as well, which didnt work.
Thanks for your help

Hi there,

This does nothing I’m afraid:
[php]<?php $text ?>[/php]

You need to do this:
[php]<?php echo $text; ?>[/php]

First of all,
after “Select”, you ovewrite (id,text) values, if only has a value, don’t do a while, if has multiples values try to use all of this not only the last.

In while yo do an “echo”, what are you looking with this, at my code i will delete this, i expect that you print this in debug mode.

Another question are why are ‘9’ in
http://www.website.co.uk/showsingle.php?id=9<?php $id?>

you try to remove this.

shake the floor try to put :
[php]

<?php $username="dbuser"; $password="dbpass"; $database="dbname"; $table="data"; $localhost="localhost"; $_SERVER['QUERY_STRING']; mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM $table WHERE id='$_GET[id]'"; $id="$_GET[id]"; $result=mysql_query($query); $temp = mysql_fetch_assoc($result); $id=$temp["id"]; $text=$temp["text"]; mysql_close(); ?> <?php $text ?> <?php echo "Database Output

";

?>

[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service