21,893
社区成员




<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$operation = $_GET['operation'];
$brand = $_GET['brand'];
if($brand == 'hp'){
$query = "SELECT * FROM laptop WHERE name like '%" . $brand . "%'";
mysql_query("SET NAMES UTF8");
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();
$i = 0;
while ($i < $num) {
$price = mysql_result($result,$i,"price");
$weight = mysql_result($result,$i,"weight");
$json = '{"laptops":{"price": "$price","weight": "$weight"}}';
$json_string = json_encode($json);
$obj = json_decode($json_string);
echo "$obj";
$i++;}
} else {
echo "error";
}
?>
<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$operation = $_GET['operation'];
$brand = $_GET['brand'];
if($brand == 'hp'){
$query = "SELECT * FROM laptop WHERE name like '%" . $brand . "%'";
mysql_query("SET NAMES UTF8");
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();
$i = 0;
while ($i < $num) {
$price = mysql_result($result,$i,"price");
$weight = mysql_result($result,$i,"weight");
$json = '{"laptops":{"price": "$price","weight": "$weight"}}';
$json_string .= json_encode($json); //连续输出
echo "$json_string";
$i++;
}
} else {
echo "error";
}
?>