我的查询工作正常.但是尝试从表中获取唯一值mysql fetch数组不起作用.
这是我的sql
A-2815是车辆的物品代码.这个领域是独特的.期待的结果是item_code A-2815的车辆细节.
$sql = "SELECT vehicle.id,item_code,make,model,vehicle_type,color,showroom_id,";
$sql .= "adding_user_Id,approved,image_1 ";
$sql .= "FROM images,vehicle ";
$sql .= "WHERE vehicle.id=images.item_id ";
$sql .= "AND (item_code LIKE '%A-2815%' ";
$sql .= "OR make LIKE '%A-2815%' ";
$sql .= "OR model LIKE '%A-2815%' ";
$sql .= "OR vehicle_type LIKE '%A-2815%' ";
$sql .= "OR color LIKE '%A-2815%' ";
$sql .= "OR showroom_id LIKE '%A-2815%') ";
$sql .= "AND activate=1 ";
$sql .= "AND type_of_image=1 ";
PHP
$query = MysqL_query($sql);
while($result = MysqL_fetch_array($query)){
echo $result['item_code'];
echo $result['make'];
echo $result['model'];
echo $result['vehicle_type'];
echo $result['color'];
echo $result['showroom_id'];
}
?>
当结果超过1行时,这工作正常.但问题是当结果是1行然后它不工作.
最佳答案
while ($result = MysqL_fetch_array($query,MysqL_ASSOC)) {
// assoc
echo $result['item_code'];
}
$connect = MysqLi_connect('localhost','root','pwd','dbname');
$sql = "select * from soMetable";
$query = MysqLi_query($connect,$sql);
while ($result = MysqLi_fetch_array($query,MysqLI_ASSOC)) {
// assoc
echo $result['item_code'];
}