2015-06-25 106 views
0

我正在使用以下ajax腳本來運行我的MySQL查詢,然後只希望jquery淡出我的div和淡入另一個如果查詢返回true否則如果查詢返回false不做任何事情。ajax運行mysql查詢並檢查mysql查詢是否爲真或假?

阿賈克斯:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $.ajax({ 
      type: "POST", 
      url: "include/fade_to_do_list.php", 
      data: "theOption=" + $(this).attr("id"), 
      dataType: 'json',//specify data type 
      success: function(data3) { 
       if(data3.res.indexOf("success") >-1){ 
        setTimeout(
         function() {  
          $("#to_do_list").fadeOut(); 
         }, 3500 
        ); 

        setTimeout(
         function() {  
          $("#compliance_list").fadeIn(); 
         }, 500 
        ); 
       } 
      } 
     }); 
    }); 
</script> 

PHP/MySQL的:

<?php 
session_start(); 
include 'config.php'; 

$query = "SELECT * FROM supplier_stats WHERE complete_count = > 3 AND user_id = '{$_SESSION['id']}'"; 
$result = mysql_query($query); 
if(mysql_num_rows($result)>0) { 
    $query2 = "UPDATE supplier_stats SET profile_complete = 'complete' WHERE user_id = '{$_SESSION['id']}'"; 
    $result2 = mysql_query($query2); 

    if($result2) { 
     $return['res'] = 'success'; 
    } else { 
} 
} 

echo json_encode($return); 
?> 

請能有人告訴我在哪裏,我錯了?我目前沒有錯誤,我的jquery只是不執行。謝謝

+0

目前會發生什麼?錯誤,如果是的話,它是什麼? – chris85

+0

@ chris85目前沒有錯誤,但我的jQuery不會執行任何方式,無論我的查詢是真或假 –

+0

它不發送請求或它沒有得到響應? – chris85

回答

0

mysql_query()總是回報你。你需要count number of affected row

而且問題是等於大於操作它用作>=

$query = "SELECT * FROM supplier_stats WHERE complete_count >= 3 AND user_id = '{$_SESSION['id']}'"; 
$result = mysql_query($query); 

$query2 = "UPDATE supplier_stats SET profile_complete = 'complete' WHERE user_id = '{$_SESSION['id']}'"; 
    $result2 = mysql_query($query2); 
    $total=mysql_affected_rows(); 

    if($total >0) { 
     $return['res'] = 'success'; 
    } else { 

}