Jump to content

Limit Problem


SkyRanger

Recommended Posts

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

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

Archived

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

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