Jump to content


Photo

Limit Problem


  • Please log in to reply
4 replies to this topic

#1 SkyRanger

SkyRanger
  • Members
  • PipPipPip
  • Advanced Member
  • 649 posts

Posted 09 September 2006 - 02:48 AM

$result = mysql_query( "SELECT * FROM ads desc limit=5") or die( "Unable to select database");

Not sure what the problem is.  What I am trying to do is show the last 5 ads that were posted
If you search for it, it may be there.

Ensure you use < > button before inserting code for easy reading.

A wise Lady Guru keeps reminding me if you have a select problem: READ THIS

#2 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 09 September 2006 - 02:53 AM

Try this:

$result  = mysql_query( "SELECT * FROM ads desc limit 5");

If you are trying to order it in descending order:

$result  = mysql_query( "SELECT * FROM ads ORDER BY ID DESC limit 5");


#3 SkyRanger

SkyRanger
  • Members
  • PipPipPip
  • Advanced Member
  • 649 posts

Posted 09 September 2006 - 03:00 AM

For some reason that is not working.

Here is what I have:

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>";
}

I keep getting:  Unable to select database

but when i take out the "ORDER BY ID DESC limit 5" it works no problem
If you search for it, it may be there.

Ensure you use < > button before inserting code for easy reading.

A wise Lady Guru keeps reminding me if you have a select problem: READ THIS

#4 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 09 September 2006 - 03:19 AM

Well, with this code that I gave you:

$result  = mysql_query( "SELECT * FROM ads ORDER BY ID DESC limit 5");

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

#5 SkyRanger

SkyRanger
  • Members
  • PipPipPip
  • Advanced Member
  • 649 posts

Posted 09 September 2006 - 03:30 AM

Stupid me, yeah forgot to fix the id problem.  Works awsome now, thanks for your help.
If you search for it, it may be there.

Ensure you use < > button before inserting code for easy reading.

A wise Lady Guru keeps reminding me if you have a select problem: READ THIS




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users