SkyRanger Posted September 9, 2006 Share Posted September 9, 2006 [code]$result = mysql_query( "SELECT * FROM ads desc limit=5") or die( "Unable to select database");[/code]Not sure what the problem is. What I am trying to do is show the last 5 ads that were posted Link to comment https://forums.phpfreaks.com/topic/20195-limit-problem/ Share on other sites More sharing options...
pocobueno1388 Posted September 9, 2006 Share Posted September 9, 2006 Try this:[code]$result = mysql_query( "SELECT * FROM ads desc limit 5");[/code]If you are trying to order it in descending order:[code]$result = mysql_query( "SELECT * FROM ads ORDER BY ID DESC limit 5");[/code] Link to comment https://forums.phpfreaks.com/topic/20195-limit-problem/#findComment-88825 Share on other sites More sharing options...
SkyRanger Posted September 9, 2006 Author Share Posted September 9, 2006 For some reason that is not working.Here is what I have:[code]include "inc/dbclass.inc.php";$connection=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$dbname");$result = mysql_query( "SELECT * FROM cf_ads ORDER BY ID DESC limit 5") or die( "Unable to select database"); $wordnum = mysql_num_rows( $result );while( $row = mysql_fetch_array( $result ) ){echo "<b>"; echo $row["adtitle"];echo "</b><br>";echo $row["adtext"];echo "<br>";echo "<a class=\"textlink\" href=classifieds/showad.php?adid=";echo $row["adid"];echo ">View Ad</a><br>";echo "<hr>";}[/code]I keep getting: [i]Unable to select database[/i]but when i take out the "ORDER BY ID DESC limit 5" it works no problem Link to comment https://forums.phpfreaks.com/topic/20195-limit-problem/#findComment-88827 Share on other sites More sharing options...
pocobueno1388 Posted September 9, 2006 Share Posted September 9, 2006 Well, with this code that I gave you:[code]$result = mysql_query( "SELECT * FROM ads ORDER BY ID DESC limit 5");[/code]You need to replace the 'ID' with an actual feild in the ads table. Unless you did just call the field 'ID'?What is your Auto increment feild in the ads table? That is what you would want to put instead of 'ID'. Link to comment https://forums.phpfreaks.com/topic/20195-limit-problem/#findComment-88830 Share on other sites More sharing options...
SkyRanger Posted September 9, 2006 Author Share Posted September 9, 2006 Stupid me, yeah forgot to fix the id problem. Works awsome now, thanks for your help. Link to comment https://forums.phpfreaks.com/topic/20195-limit-problem/#findComment-88833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.