无法将内爆变量包含在数组中以运行查询

时间:2015-05-11 07:20:55

标签: php mysql pdo

我不确定我的头衔是否恰如其分。然而,这是我的问题.Below查询遍历数组并返回所有6条记录(每个id 3条记录)。

但是当我替换

$key = array(1,2)  with
$a=$data['sub'];

foreach($a as $v=>$k) 
  {

    $key0[]=$v;

  }
 $key2=implode(',',$key0);

它只返回1个id的结果。我想知道为什么,实际上echo $key2等于1,2

$postcode=$data['postcode'];
$rate=$data['slider1'];
**$key = array(1,2);**
$in = join(',', array_fill(0, count($key), '?'));

$statement = $pdo->prepare("SELECT * FROM posts WHERE posts.subid IN (".$in.") AND posts.pricing=?  AND posts.Poscode=? ORDER BY posts.Poscode DESC LIMIT 60");
$result = array_merge($key, array($rate,$postcode));
$statement->execute($result);
$json = array();
while( $row = $statement->fetch()) {
    array_push($json, array("name" => $row['Name'], "id" => $row['PostUUID'],"rate" => $row['pricing'],"postcode" => $row['Poscode'],"reputation" => $row['Reputation'],"plus" => $row['ReviewPlus'],"neg" => $row['ReviewNeg'],"weekM" => $row['week_morning'],"weekA" => $row['week_afternoon'],"weekE" => $row['week_evening'],"endM" => $row['weekend_morning'],"endA" => $row['weekend_afternoon'],"endE" => $row['weekend_evening']));
}

0 个答案:

没有答案