Nita Nita - 1 year ago 74
MySQL Question

Display values from php mysql array separately

What im trying to do is to save vales of "option" from all records in array to be able to echo them out later. I don't know how to display them seperatly. Feel stuck. Any sugestions?

My code:

$result = $mysqli->query("SELECT option FROM `myoptions` WHERE id IN (1, 7, 18, 24);");
$row = array();
while($row = $result->fetch_array()) {
echo $row[] = $row["option"];

echo $option1 = $row[0];
echo $option2 = $row[1];
echo $option3 = $row[2];
echo $option4 = $row[3];

Answer Source

YOu should store the value in an array

$cnt = 0;
while($row = $result->fetch_array())  { 

  $for_future_use[$cnt] = $row["option"]; 

and then use later

foreach($for_future_use as $key=>$value) {
   echo $value;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download