2015-11-06 66 views
-1

我在mysqli的真小白,所以我需要幫助..mysqli的LEFT JOIN計數

請幫我轉換這個MySQL到mysqli的 ...我不出來..

$new_mail = mysql_result(
        mysql_query(
         "SELECT COUNT(*) FROM `mail` 
          LEFT JOIN `contact` ON `mail`.`user_id` = `contact`.`from_id` 
               AND `contact`.`user_id` = '$user_id 
         WHERE `mail`.`from_id` = '$user_id' 
          AND `mail`.`read` = '0' 
          AND `mail`.`delete` != '$user_id' 
          AND `contact`.`ban` != '1'") 
       , 0); 
if ($new_mail) 
    $list[] = '<a href="link">Message - $new_mail </a>' 
+0

查詢不變,請學習_SQL injection_。使用預準備的語句PDO和MySQLi都有它們。 – Rudie

回答

0

我轉換... TNX反正:)

$new_mail = mysqli_fetch_array(mysqli_query($db, "SELECT COUNT(*) FROM `mail` LEFT JOIN `contact` ON `mail`.`user_id`=`contact`.`from_id` AND `contact`.`user_id`='$user_id' WHERE `mail`.`from_id`='$user_id' AND `mail`.`obrisano`!='$user_id' AND `contact`.`ban`!='1'")); 

@ryan我只是想給MySQL查詢mysqli的轉換,但TNX :)