rockinaway Posted May 12, 2007 Share Posted May 12, 2007 $articles = db_query(" SELECT date, author, subject, body, id FROM {$db_prefix}tp_articles ORDER BY date DESC LIMIT 0,2", __FILE__,__LINE__); That is my code, I want the latest article but when I have the LIMIT set to 0,1 then no article is shown, even though there is a newer article.. what could be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/51074-solved-smf-problem-with-limit/ Share on other sites More sharing options...
toplay Posted May 12, 2007 Share Posted May 12, 2007 You can just use "limit 1" also "date" is a reserved word in MySQL so you should change the column name to something more meaningful or enclose the column name in backtick marks (i.e. `date`). Try the query outside of php code first (like using sqlyog or phpmyadmin). When it works there, put it into the code. As part of debugging this, display the full query to make sure it's what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/51074-solved-smf-problem-with-limit/#findComment-251427 Share on other sites More sharing options...
rockinaway Posted May 12, 2007 Author Share Posted May 12, 2007 It works in phpMyAdmin, but not in the file or webpage :S Quote Link to comment https://forums.phpfreaks.com/topic/51074-solved-smf-problem-with-limit/#findComment-251469 Share on other sites More sharing options...
bubblegum.anarchy Posted May 12, 2007 Share Posted May 12, 2007 Make this change: $articles = db_query($query = " SELECT date, author, subject, body, id FROM {$db_prefix}tp_articles ORDER BY date DESC LIMIT 0,2", __FILE__,__LINE__); print '<PRE>'.$query.'</PRE>'; And post the query here. Quote Link to comment https://forums.phpfreaks.com/topic/51074-solved-smf-problem-with-limit/#findComment-251673 Share on other sites More sharing options...
rockinaway Posted May 13, 2007 Author Share Posted May 13, 2007 SELECT date, author, subject, body, id FROM smf_tp_articles ORDER BY date DESC LIMIT 0,2 That is what it returns.... :S Quote Link to comment https://forums.phpfreaks.com/topic/51074-solved-smf-problem-with-limit/#findComment-251868 Share on other sites More sharing options...
bubblegum.anarchy Posted May 14, 2007 Share Posted May 14, 2007 What happens when you add backticks to the date column? $articles = db_query(" SELECT `date`, author, subject, body, id FROM {$db_prefix}tp_articles ORDER BY date DESC LIMIT 0,2", __FILE__,__LINE__); Quote Link to comment https://forums.phpfreaks.com/topic/51074-solved-smf-problem-with-limit/#findComment-252469 Share on other sites More sharing options...
rockinaway Posted May 14, 2007 Author Share Posted May 14, 2007 Fixed ... it was due to another mysql_fetch_array called earlier in the script. Quote Link to comment https://forums.phpfreaks.com/topic/51074-solved-smf-problem-with-limit/#findComment-252791 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.