Jump to content


Photo

Simple MySQL Query Help


  • Please log in to reply
3 replies to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 17 June 2006 - 12:38 PM

Hi,

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

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 June 2006 - 12:51 PM

Just a matter of precedence:
$sql = "SELECT * FROM `tutorials' WHERE `activation` = 1 ORDER BY `id` DESC LIMIT 5";

Legend has it that reading the manual never killed anyone.
My site

#3 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 17 June 2006 - 01:39 PM

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]

$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)){


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 June 2006 - 01:58 PM

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

Use this instead:
$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

At least you'll be able to see the exact query used - that should help you find any problems if they still exist.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users