PHP Mysql Query正在运行但不显示任何数据

时间:2014-05-23 07:53:41

标签: javascript php mysql json

您好我已设计了多个复选框选项的代码。复选框选项显示,我的查询也在运行。但我无法显示所有数据,以便我可以从我的复选框选项中过滤它。可以找到此代码here。代码2正在为我运行,但我想从代码1逻辑运行它。请帮助。

Code1逻辑不起作用:

<?php 
require 'Database.php';
#### TEMP SET NAMES FÜR UTF8 ###################################################
include 'Json.php';
$opts = $_POST['filterOpts'];
$tmp = array();
foreach ($opts as $opt) {
    $tmp[] = '"'.$opt.'"';
}
echo $query = 
    'SELECT mobile_phone.id, name, model, price FROM mobile_phone INNER JOIN brand ON brand_id = brand.id WHERE name IN  ('.implode(",", $tmp).')';


$result = mysql_query($query);
$data   = array();
while ($row = mysql_fetch_assoc($result)) {
    $data[] = var_dump($row);
}

echo json_encode($data);
?>

运行Code2逻辑:

<?php 
  $pdo = new PDO('mysql:host=localhost;dbname=sitepoint', 'root', '*****');
  $opts = $_POST['filterOpts'];
  $qMarks = str_repeat('?,', count($opts) - 1) . '?';
  $statement = $pdo->prepare("SELECT mobile_phone.id, name, model, price FROM mobile_phone INNER JOIN brand ON brand_id = brand.id WHERE name IN ($qMarks)");
  $statement -> execute($opts);
  $results = $statement -> fetchAll(PDO::FETCH_ASSOC);
  $json = json_encode($results);
  echo($json);
?>

0 个答案:

没有答案