Jump to content

Archived

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

lpxxfaintxx

Simple MySQL Query Help

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. :)

Share this post


Link to post
Share on other sites
Just a matter of precedence:
[code]$sql = "SELECT * FROM `tutorials' WHERE `activation` = 1 ORDER BY `id` DESC LIMIT 5";[/code]

Share this post


Link to post
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]

Share this post


Link to post
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.

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.