2017-09-13 66 views
-1

給予當我運行下面的查詢mysqli_query()預計參數1是mysqli的,數組中

$sql ="SELECT * FROM user_info JOIN Notifications ON user_info.user_info_id =Notifications.Sender_id AND Notifications.STATE=0 LIMIT 1"; 
$query=mysqli_query($con,$sql); 
$num_rows=mysqli_num_rows($query); 
$message='' 

if($num_rows > 0){ 
    $con=mysqli_fetch_assoc($query); 
    switch ($con['Notification_Type']){ 
     case'events': 
      $var="Notifications".$con['user_info_id']; 
      $sql_shown="SELECT *FROMevent WHERE event.notification_shown = 0 AND event.user_info_id='$var'LIMIT 1"; 
      $query_vi=mysqli_query($con,$sql_shown); 
      $num_rows_vi=mysqli_num_rows($query_vi); 
      $message.=$con['Sender_id']."has created a Event"; 
      echo $message; 
     break; 
    } 
} 

我收到以下錯誤:

mysqli_query() expects parameter 1 to be mysqli, array given in

這是我的用戶表:

CREATE TABLE IF NOT EXISTS user_info(
    user_info_id INT(11) NOT NULL AUTO_INCREMENT, 
    u_first_name VARCHAR(255) NOT NULL, 
    u_last_name VARCHAR(255) NOT NULL, 
    u_email VARCHAR(255) NOT NULL, 
    u_mobile VARCHAR(255) NOT NULL, 
    role ENUM('1yearM','1yearN','1yearR','1yearU','1yearS','2M','2R','2N','2U','2S','3M','3R','3N','3U','3S','4M','4R','4N','4U','4S','professor','librarian','admission_department') NOT NULL, 
    password VARCHAR(255) NOT NULL, 
    u_ip VARCHAR(255) NOT NULL, 
    signup_date DATETIME NOT NULL, 
    last_login DATETIME NOT NULL, 
    act_code VARCHAR(255) NOT NULL, 
    activation enum('1','0') NOT NULL DEFAULT '0', 
    PRIMARY KEY (user_info_id), 
    UNIQUE KEY (u_email,u_mobile) 
) 

這是我的事件表:

CREATE TABLE IF NOT EXISTS Event(
    Event_id INT(11) NOT NULL AUTO_INCREMENT, 
    Event_Name VARCHAR(255) NOT NULL, 
    Event_location VARCHAR(255) NOT NULL, 
    Event_Organizer VARCHAR(255) NOT NULL,  
    Event_Date_Posted DATETIME NOT NULL, 
    Event_Starting_timings DATETIME NOT NULL, 
    Event_Ending_timings DATETIME NOT NULL, 
    Event_Day VARCHAR(255) NOT NULL, 
    Event_Description text NOT NULL, 
    Event_file_name VARCHAR(255) NOT NULL, 
    Event_file_path VARCHAR(255) NOT NULL, 
    Event_file_size VARCHAR(255) NOT NULL, 
    user_info_id INT(11) NOT NULL, 
    notification_shown ENUM('1','0') NOT NULL DEFAULT '0', 
    PRIMARY KEY (Event_id), 
    FOREIGN KEY (user_info_id) REFERENCES user_info(user_info_id)  
) 

這是我的通知表:

CREATE TABLE IF NOT EXISTS Notifications(
    Notifications_id INT(11) NOT NULL AUTO_INCREMENT, 
    Notification_Type VARCHAR(255) NOT NULL, 
    Notification_Content VARCHAR(255) NOT NULL, 
    Notification_Created_Date DATETIME NOT NULL, 
    Notification_State ENUM('read','unread') NOT NULL DEFAULT 'unread', 
    Is_Notification_Delete ENUM('1','0') NOT NULL DEFAULT '0', 
    Notification_Deleted_Date DATETIME NOT NULL, 
    Sender_id INT(11) NOT NULL, 
    STATE ENUM('1','0') NOT NULL DEFAULT '0', 
    Recipient_id INT(11) NOT NULL, 
    PRIMARY KEY (Notifications_id) 
) 

回答

0

檢查您$con它被用正確的方法mysqli_connect('')創建。

1

你覆蓋你$con變量這一行:

$con=mysqli_fetch_assoc($query); 

該行之前,您$con變量是一個有效的MySQLi連接句柄。在那行之後它不是一個數組。因此,你的mysqli_query()調用抱怨說,第一個參數不再是mysqli連接/對象/句柄,而是現在是一個數組(它不應該)。

與庫MySQLi連接/對象更改$con=mysqli_fetch_assoc($query);所以它不會覆蓋$con變量/處理,而是寫的結果不同的變量(也許$userinfo?)。

相關問題