Jump to content
xisto Community
Sign in to follow this  
Corey

..php..mysql..problem

Recommended Posts

i have a problem with this script...

it should display a content from a row in mysql database...defined by variable $id

<?phpinclude "db.php";$query = "SELECT title, content FROM articles WHERE id='$id'";$article=mysql_query($query);while ($r=mysql_fetch_array($article)){$title=$r["title"];$content=$r["content"];echo "<b>$title</b>";echo "<br><br>$content";}?>

the problem is that it displays only the content from the last row in the mysql database...but not the content defined by $id (...WHERE id=$id...)

....something is strange...because the script worked in the morning...and i've changed something...and it doesn't..???


then i uploaded the old file on the server (that worked) and nothing?..the same thing again...


please help me....

btw
the script is a part of "article system"...

Share this post


Link to post
Share on other sites

This is the way I would code your script >_>

<?phpinclude 'db.php';$article=mysql_query('SELECT title, content FROM articles WHERE id = \''.$id.'\'');while ($r=mysql_fetch_array($article))  echo '<b>'.$r['title'].'</b><br /><br />'.$r['content'];?>

Don't waste your time coding unessesary stuff like extra variables or two echo functions when you only need one. BTW using single quotes is faster :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.