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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.