0

我想在准备语句中发送数组值,但它不起作用

我的代码是:

for($bb=0; $bb<sizeof($subject_temp_array)-1; $bb++)
 {
    $sql ="select * from tbl_subjects where sub_id = ?";
    if ($result = $mysqli->prepare($sql)) 
    {
       $subject_id = $subject_temp_array[$bb];
       $result -> bind_param("i",$subject_id); 
       $result->execute();
       $result->store_result();
       $rows1 = $result->num_rows;
     }
  }
4

1 回答 1

-1

为什么不使用foreach?另外,您是否遇到任何错误消息?试试这个代码:

error_reporting(-1);
ini_set('display_errors', 1);

foreach($subject_temp_array as $subject_id)
{
    $sql = "select * from tbl_subjects where sub_id = ?";
    if ($result = $mysqli->prepare($sql)) 
    {
       $result->bind_param("i", $subject_id); 
       $result->execute();
       $result->store_result();
       $rows1 = $result->num_rows;
     } else {
         throw new Exception("Error preparing query.");
     }
}
于 2012-09-29T13:44:50.187 回答