Jump to content

Archived

This topic is now archived and is closed to further replies.

SkyRanger

Limit Problem

Recommended Posts

[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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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'.

Share this post


Link to post
Share on other sites

×

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.