1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.