Get Id Number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Get Id Number

Post by blacksnday »

If I do something like

Code: Select all

$sql = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 5");
How do I get the ID number for each of the 5 items to print on page?
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

Code: Select all

while ($row = mysql_fetch_array($sql))
{
  //Do what you want here. Each column name is the associative index to $row which is an array
  echo $row['id'];
}
That simply outputs the 5 id numbers
Post Reply