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?

4

1 回答 1

1

你不查询 mysql_fetch_array。Mysql_query 给出了你使用 mysql_fetch_array 的结果。所以正确的代码是:

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

但是, $q3 将是一个数组,这可能不是您想要的。此外,如果使用诸如 PDO (http://www.php.net/manual/en/class.pdo.php) 之类的抽象会更好。这将最大限度地提高性能并提高安全性。

于 2012-10-07T15:48:41.537 回答