2012-07-13 62 views
0

我得到这个错误,并不能为我的生命弄清楚为什么错误是:的mysqli ::查询()预计参数1是字符串

Warning: mysqli::query() expects parameter 1 to be string, object given in ... on line 34

导致

Fatal error: Call to a member function fetch_array() on a non-object in ... on line 36

这里是我的代码

$products = $mysqli->real_escape_string($_GET['products']); 
$query_cat = 'SELECT DISTINCT `Category` FROM `products` where `Type`="'. $products. '"'; //for cotegories 
$cat_id = cat($query_cat); 

这产生一个字符串,SELECT DISTINCT Category FROM products,其中Type =“面包店”(由回声确认) ,这里是有问题的功能

function cat($query_cat){ 
    global $mysqli; 
    $result = $mysqli->query($query_cat); //line 34 
    $i='0'; 
    while ($row = $result->fetch_array(MYSQLI_ASSOC)){ 
     $i++; 
     $id[$i] = $row["Category"]; 
    } 
    $result->close(); 
    return $id; 
} 

但这个工程

function cat($query_cat){ 
    global $mysqli; //echo $query_cat here will give correct query 
    $products = $mysqli->real_escape_string($_GET['products']); 
    $query_cat = 'SELECT DISTINCT `Category` FROM `products` where `Type`="'. $products. '"'; //for cotegories 
    $result = $mysqli->query($query_cat); 
    $i='1'; 
    while ($row = $result->fetch_array(MYSQLI_ASSOC)){ 
     $id[$i] = $row["Category"]; 
     $i++; 
    } 
    $result->close(); 
    return $id; 
} 
+0

请,学会用准备好的发言,并根据全局状态 – 2012-07-13 17:01:25

+0

如果你高亮线34 – andrewsi 2012-07-13 17:05:18

+1

@andrewsi再看这可能有助于阻止.... – 2012-07-13 17:05:49

回答

0

出现了倒闭的函数调用我的代码中的其他地方的任何不便

对不起
相关问题