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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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