Help with MySQL query and in_array

What I am trying to do is reference a MySQL table and get ALL of the values from the rows with a specific mysql_query in an array. The standard mysql_fetch_array or mysql_fetch_assoc gives me the first row like it should.

Of course if I pull a while command. I can get individual values from the mysql query. I need all the values in an array so I can use in_array to look for a time (for example, 8a_9a) in the day I set (for example, mon)


$info = mysql_query("SELECT day,time FROM avail WHERE user='".$_GET['id']."' AND day='mon' AND active='1'");

$info_row=mysql_fetch_array($info);


Which returns an array of

Array ([0] => mon [day] => mon [1] => 11a_12p [time] => 11a_12p )

even though I have 9a_10a, 11a_12p, and 3p_4p tied with that user id.

Here is a sample of in_array looking for a specific value


<input type="checkbox" name="amon" value="9a_10a"<?php if (in_array('9a_10a', $info_row)) { echo ' checked="checked"'; } ?>>
<input type="checkbox" name="amon" value="10a_11a"<?php if  (in_array('10a_11a', $info_row)) { echo ' checked="checked"'; } ?>>
<input type="checkbox" name="amon" value="11a_12p"<?php if  (in_array('11a_12p', $info_row)) { echo ' checked="checked"'; } ?>>

I am utterly confused so if anyone has a better solution, that would be great

You can add the times to an array, then check that array.


$times = array();
while (row = mysql_fetch_array($info)) {
    $times[] = $row['time'];
}
...
if (in_array('9a_10a', $times)) { ... }

Thanks for your help. My mind is mush at the end of the day and your method worked with no problems.