Jump to content

Fetching an array from MYSQL using while


mb326

Recommended Posts

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";

    }

  }

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.