Jump to content


Photo

Last row from db


  • Please log in to reply
2 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 20 September 2006 - 01:59 PM

Hi guys,
I have a very simple question: how can I echo the last row from db?

Thanks for your time,
George
I don't need your script, I'll try to write it myself

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 20 September 2006 - 02:04 PM

if you have an auto-incrementing id field, you can simply sort by that field:
<?php
$sql = mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT 1");
$row = mysql_fetch_row($sql);
foreach ($row as $key => $val) echo "$key => $val<br />\n";
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 20 September 2006 - 02:09 PM

Thanks obsidian, think it will help me  ;)
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users