Jump to content

[SOLVED] Collecting only the last(newest) entry... from a MySQL DB using PHP.


jimdidr

Recommended Posts

hello its newbie me again, I'am having problems finding or maby understanding the code for fetching ONLY the last entry made into a database...

 

I used a MySQL/PHP generator, I know thats probably frowned upon but it helps me learn quicker then reading hypotheticals...

My problem is now that that generator gave me a PHP loop that gives med all the entries... i however only want the last one on my front page, (I will make a archive later.)

 

I found a tutorial that sayes the while() code is what makes everything loop until the DB has no more entries, how do i stop that loop after the first(the latest entrie) has been ECHOed??

 

 

Thank you for any and all help..

hmm i guess is messed that up

 

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/home/jim/public_html/foto/sliced/kolasj.new2.php on line 56

The database is empty

"

 

$query="LIMIT 1 SELECT * FROM db_name ";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();

 

This is line 54, 55, 56 and 57 of the code...

 

I tryd putting LIMIT 1 before and after SELECT inside the brachets, didnt seem to make a difference to the error...

 

 

EDIT: If it matters my while query is

 while ($i < $num) 

i didnt check that it was the same as the tutorial i was looking at :/ sorry.

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.