2012-07-13 66 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

出現了倒閉的函數調用我的代碼中的其他地方的任何不便

對不起
相關問題