mb326 Posted April 10, 2008 Share Posted April 10, 2008 Another fetching array problem. This function prints the values of the array twice, with a foreach loop and, if I try it with just a while loop and reference the $result, I get no number, just the 'Maximum' and 'Minimum' attendance labels. How can I retrieve just 1 iteration of these items with their values printed out as well? /* List min and max amount of tickets that can be sold for this event */ public function listEventStats($eventID) { $this->eventID = $eventID; $eventStats = mysqli_query($this->db, "SELECT max_attend, min_attend FROM EventCalendar WHERE eventID = $eventID"); if(!$eventStats) { echo "Please enter the correct eventID\n"; } else { // now fetch the result while($result = mysqli_fetch_array($eventStats, MYSQL_NUM)) { // print out the values foreach($result as $value) { echo "Maximum Attendance: {$value['max_attend']} \n"; echo "Minimum Accendance: {$value['min_attend']} \n"; } } } Link to comment https://forums.phpfreaks.com/topic/100461-fetching-an-array-from-mysql-using-while/ Share on other sites More sharing options...
friedemann_bach Posted April 10, 2008 Share Posted April 10, 2008 Try: while($result = mysqli_fetch_object($eventStats)) { // print out the values echo "Maximum Attendance: $result->max_attend\n"; echo "Minimum Accendance: $result->min_attend\n"; } } Link to comment https://forums.phpfreaks.com/topic/100461-fetching-an-array-from-mysql-using-while/#findComment-513754 Share on other sites More sharing options...
mb326 Posted April 10, 2008 Author Share Posted April 10, 2008 Thankyou, that worked a treat! Link to comment https://forums.phpfreaks.com/topic/100461-fetching-an-array-from-mysql-using-while/#findComment-514273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.