我正在尝试使用Android应用程序的JSON从复选框列表中过滤。出于测试目的,我使用了 html 复选框。我收到错误,因为
注意:数组到字符串的转换警告:mysql_fetch_array() 期望参数 1 是资源,布尔值
我的代码是 require("config.inc.php"); if (!empty($_POST)) {
$condition ="; $value="; $response = 数组();
if(!empty($_POST['brand'])){ $value = _POST 美元["品牌"]; $valu = 内爆("','", $value); $condition .= "PhoneMake In "."("$valu")"; } if(!empty($_POST['ram'])){ $value = $_POST['公羊']; $valu = 内爆("','", $value); $condition .= " 和 Os_ram IN "."("$valu")";
}
$query ="SELECT * FROM product INNTER JOIN specs WHERE "." $condition GROUP BY PhoneModel";
$query_params = array(
':PhoneMake' => $_POST['brand'],
':Os_ram' => $_POST['ram']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error2. Please Try Again!";
die(json_encode($response));
}
$a = mysql_query($query);
while($b = mysql_fetch_array($a))
{
$response["$b[PhoneMake]"][]["$b[PhoneModel]"] = array('OS' => $b['Os_name'], 'Display Size (Inch)' => $b['D_apps'], 'Ram' => $b['Os_ram']);
}
echo json_encode($response);
}
?>
<h1>Filter</h1>
<form action="" method="post">
<div class="panel-heading filterhead">Filter by brand</div>
<label><input type="checkbox" name="brand[]" value="Motorola"> Motorola</label><br>
<label><input type="checkbox" name="brand[]" value="Xolo"> Xolo</label><br>
</div>
<div class="panel-heading filterhead">RAM</div>
<label><input type="checkbox" name="ram[]" value="512"> 512 MB</label><br>
<label><input type="checkbox" name="ram[]" value="1"> 1 GB</label><br>
</div>
</div>
<input type="submit" value="Filter" />
</form>
配置.inc.php
<?php
$host = "localhost";
$dbname = "street";
$username = "root";
$password = "";
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try
{
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
}
catch(PDOException $ex)
{
die("Failed to connect to the database: " . $ex->getMessage());
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
function undo_magic_quotes_gpc(&$array)
{
foreach($array as &$value)
{
if(is_array($value))
{
undo_magic_quotes_gpc($value);
}
else
{
$value = stripslashes($value);
}
}
}
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
}
header('Content-Type: text/html; charset=utf-8');
session_start();
?>
我已经正确编码了所有内容,但仍然遇到错误。主要问题是 mysql_fetch_array() 期望参数 1 是资源,布尔值。帮助我摆脱这个错误。我想按原样使用 config.inc.php 文件。
您的查询中似乎有拼写错误。 INNTER JOIN
应该是INNER JOIN
.