lpxxfaintxx Posted June 17, 2006 Share Posted June 17, 2006 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 More sharing options...
AndyB Posted June 17, 2006 Share Posted June 17, 2006 Just a matter of precedence:[code]$sql = "SELECT * FROM `tutorials' WHERE `activation` = 1 ORDER BY `id` DESC LIMIT 5";[/code] Link to comment https://forums.phpfreaks.com/topic/12231-simple-mysql-query-help/#findComment-46631 Share on other sites More sharing options...
lpxxfaintxx Posted June 17, 2006 Author Share Posted June 17, 2006 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 https://forums.phpfreaks.com/topic/12231-simple-mysql-query-help/#findComment-46643 Share on other sites More sharing options...
AndyB Posted June 17, 2006 Share Posted June 17, 2006 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 https://forums.phpfreaks.com/topic/12231-simple-mysql-query-help/#findComment-46648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.