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
https://forums.phpfreaks.com/topic/12231-simple-mysql-query-help/
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]
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.

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.