So basicly this is my code:

echo "<SELECT>";
foreach($arr_res as $op) {
   $q3 = mysql_query(mysql_fetch_array("SELECT SL_TIME FROM SLOTS WHERE SL_ID='$op'"));
   echo "<OPTION value=".$op.">".$q3."</OPTION>";
}
echo "</SELECT>";

$arr_res is the resulting array of an array_diff. It has only numerical values which are the SL_ID from my timeslots.. I want to show SL_TIME but the result I get is the $q3 producing empty result.. Why isn't this working?

share|improve this question

1 Answer

up vote 1 down vote accepted

You don't query mysql_fetch_array. Mysql_query gives an result on wich you use mysql_fetch_array. So the correct code would be:

echo "<SELECT>";
foreach($arr_res as $op){
$result = mysql_query("SELECT SL_TIME FROM SLOTS WHERE SL_ID='$op'");
$q3=mysql_fetch_array($result);
echo "<OPTION value=".$op.">".$q3."</OPTION>";
}
echo "</SELECT>";

However, $q3 will be an array, which is probably not what you want. In addition it would be a lot better if use an abstraction such as PDO (http://www.php.net/manual/en/class.pdo.php). This will maximize performance and increase the security.

share|improve this answer
Allthough copy and pasting your solution didn't directly work with a few minor adaptations it did fix the problem! Thank you so much! :) (too low to upvote sorry) – Jake Rowsell Oct 7 '12 at 15:54

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.