RRWD Posted July 13, 2013 Share Posted July 13, 2013 So I'm working on a bit of code that is supose to grab information and then run a loop. I've written something like this in the past but for some reason I cannot get it to work propery. I know I'm most likely missing something small but I can't find it. A fresh pair of eyes couldn't hurt. When I run it I get a blank page no error message. $query = "SELECT * FROM tbl_chapters ";$query .= "WHERE State = 'CA' ";$result_set = mysql_query($query, $connection);confirm_query($result_set);$chapter_set = mysql_fetch_array($result_set);return $chapter_set; while ($row = mysql_fetch_array($chapter_set)) { echo $row["Chapter"];} Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/280115-while-loop-problem/ Share on other sites More sharing options...
Philip Posted July 13, 2013 Share Posted July 13, 2013 Well.. you're returning (return $chapter_set;) before the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/280115-while-loop-problem/#findComment-1440562 Share on other sites More sharing options...
RRWD Posted July 13, 2013 Author Share Posted July 13, 2013 it was set up like that because it was on a function.php page, which is what is needed. Right? I did comment it out and change it to result_set and it looped so we are getting somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/280115-while-loop-problem/#findComment-1440564 Share on other sites More sharing options...
_EmilsM Posted July 13, 2013 Share Posted July 13, 2013 $reurnArray = Array(); while ($row = mysql_fetch_array($chapter_set)) { $returnArray[] = $row["Chapter"]; } return $returnArray; Quote Link to comment https://forums.phpfreaks.com/topic/280115-while-loop-problem/#findComment-1440578 Share on other sites More sharing options...
web_craftsman Posted July 13, 2013 Share Posted July 13, 2013 _EmilsM , mysql_fetch_assoc is a better function for this. If you don't consider, of course, that mysql_ extension is deprecated by now... Quote Link to comment https://forums.phpfreaks.com/topic/280115-while-loop-problem/#findComment-1440579 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.