php
  • mysql
  • 2013-08-03 236 views 0 likes 
    0

    我知道$ wins應該是3.因爲我在表「winner_teams」的「win」列中有3個整數爲「1」的行,但由於某些原因,此代碼不起作用。你能找到問題嗎?另外,我知道其中一些已經被玷污了。至少在工作狀態下,我會更新整個頁面。查詢沒有返回任何結果

    <?php 
    $sql = "SELECT SUM(win) FROM rated_teams WHERE server='$server' AND name='$myteam'"; 
    $query = mysql_query($sql, $con) 
    or die('A error occured: ' . mysql_error());  
    while ((mysql_fetch_array($query)))  {       
    $wins = $row['SUM(win)'];      
    } 
    ?> 
    <h3>Total Wins: <?php echo $wins?> </h3> 
    

    回答

    2

    嘗試用

    $sql = "SELECT SUM(win) as sum FROM rated_teams WHERE server='$server' AND name='$myteam'"; 
    

    而你越來越像給

    while ($row = mysql_fetch_array($query)) {       
        $wins = $row['sum'];      
    } 
    

    而我的建議是儘量避免mysql_*功能,因爲它們是deprecated.Instead使用mysqli_*功能或PDO statements

    +0

    ,你那得到它! – CSharpMinor

    0

    您不設置$行變量。編輯你的這一點。

    while ($row = mysql_fetch_array($query)) 
    
    0

    你需要給你的計算列一個別名。試試這個:

    <?php 
    $sql = "SELECT SUM(win) as sumwin FROM rated_teams WHERE server='$server' AND name='$myteam'"; 
    $query = mysql_query($sql, $con) or die('A error occured: ' . mysql_error());  
    while ($row = mysql_fetch_array($query))  {       
    $wins = $row['sumwin'];      
    } 
    ?> 
    <h3>Total Wins: <?php echo $wins?> </h3> 
    
    0

    請寫sql查詢權的方式。寫這樣的。

    $sql = "SELECT SUM(win) as sumwin FROM rated_teams WHERE server='".$server."' AND name='".$myteam."'"; 
    
    0
    while ((mysql_fetch_array($query))) { 
    

    應該

    while ($row = mysql_fetch_array($query)) { 
    
    相關問題