craigory83 Posted March 21, 2011 Share Posted March 21, 2011 Hello! First post. I am trying to code out a news website (kinda) I can't seem to fetch the news articles out of SQL. What am I doing wrong? (start is fetched by $_REQUEST. Assume it is 1) $end=$start+5; $stories = mysql_query("SELECT * FROM 'stories' DESC ORDER BY id LIMIT $start, $end"); $num = mysql_num_rows($stories); print $num; Quote Link to comment https://forums.phpfreaks.com/topic/231243-mysql-query/ Share on other sites More sharing options...
doddsey_65 Posted March 21, 2011 Share Posted March 21, 2011 $end=$start+5; $stories = mysql_query("SELECT * FROM stories ORDER BY id DESC LIMIT $start, $end") or die(mysql_error()); $num = mysql_num_rows($stories); print $num; hint* Use or die mysql_error() to print any errors that are within your query. Give that a go and let me know if it works Quote Link to comment https://forums.phpfreaks.com/topic/231243-mysql-query/#findComment-1190166 Share on other sites More sharing options...
craigory83 Posted March 21, 2011 Author Share Posted March 21, 2011 Thanks. I'm realllly new to this whole thing, but want to give it a good shot. I've read about the die() function, but never really looked into it enough to impliment it. There is no error, but num is 0 so apparently I am screwing up in my variables. Quote Link to comment https://forums.phpfreaks.com/topic/231243-mysql-query/#findComment-1190167 Share on other sites More sharing options...
doddsey_65 Posted March 21, 2011 Share Posted March 21, 2011 echo out your query and see what it prints: echo "SELECT * FROM stories ORDER BY id DESC LIMIT $start, $end"; Quote Link to comment https://forums.phpfreaks.com/topic/231243-mysql-query/#findComment-1190168 Share on other sites More sharing options...
craigory83 Posted March 21, 2011 Author Share Posted March 21, 2011 I took off 1 from $start and $end and it seems to work now. Do php and mysql have different ideas of it? Quote Link to comment https://forums.phpfreaks.com/topic/231243-mysql-query/#findComment-1190169 Share on other sites More sharing options...
doddsey_65 Posted March 21, 2011 Share Posted March 21, 2011 if $start was 1 then it would show the records from the table begining with the second. in order to show the first record you must set start to 0. so if start is 0 and end is 5 it would show records 0,1,2,3,4 Quote Link to comment https://forums.phpfreaks.com/topic/231243-mysql-query/#findComment-1190170 Share on other sites More sharing options...
craigory83 Posted March 21, 2011 Author Share Posted March 21, 2011 That is different. So if I remove 1 from the $start variable it should work swimmingly. Thank you very much sir! Quote Link to comment https://forums.phpfreaks.com/topic/231243-mysql-query/#findComment-1190173 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.