Jump to content

Simple MySQL Query Help


lpxxfaintxx

Recommended Posts

Hi,

I tried doing this:
[code]
$sql = "SELECT * FROM `tutorials` ORDER BY `id` DESC LIMIT 5 WHERE `activation` = 1";
[/code]

but it didn't work. Is there any alternatives to this?... the "activation=1" part is a very important part, as well as the DESC LIMIT 5. (It is basically saying, select the latest 5 from tutorials, where it is activated.)

Help would be appreciated. :)
Link to comment
Share on other sites

Err.. I got an error..

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/informed/public_html/projects/tuts/index.php on line 114[/quote]

[code]
$sql = "SELECT * FROM `tutorials' WHERE `activation` = '1' ORDER BY `id` DESC LIMIT 5";
$result=mysql_query($sql);


(line 114)while($rows=mysql_fetch_array($result)){ [/code]
Link to comment
Share on other sites

My mistake. Stupid backticks .... ` and ' not the same.

Use this instead:
[code]$sql = "SELECT * FROM tutorials WHERE activation = '1' ORDER BY id DESC LIMIT 5";
$result=mysql_query($sql) or die("Error: mysql_error(). " with query ". $sql); // let's see what went wrong[/code]

At least you'll be able to see the exact query used - that should help you find any problems if they still exist.
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.