jimdidr Posted September 7, 2008 Share Posted September 7, 2008 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.. Quote Link to comment Share on other sites More sharing options...
Mchl Posted September 7, 2008 Share Posted September 7, 2008 Use LIMIT 1 in your SELECT query to get only one result. Quote Link to comment Share on other sites More sharing options...
jimdidr Posted September 7, 2008 Author Share Posted September 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted September 7, 2008 Share Posted September 7, 2008 SELECT * FROM db_name ORDER BY foo DESC LIMIT 1 Instead of foo insert a field name (probably an ID) that will be used for sorting. Quote Link to comment Share on other sites More sharing options...
jimdidr Posted September 7, 2008 Author Share Posted September 7, 2008 Thank you VERY MUCH, Love you man... uhm not in that way... Wow this is aquerd... Thank you also for you patience Quote Link to comment Share on other sites More sharing options...
Mchl Posted September 7, 2008 Share Posted September 7, 2008 Glad it's not 'that' way'... Bookmark this url: http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html and take care Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.