2013-10-08 78 views
-1

心中已經得到了一些代碼,但一直得到錯誤的也是我新的PHP所以任何幫助將是巨大的:)SQL查詢提取錯誤

這裏是我的代碼

<?php 
// Create connection 
$con = mysqli_connect("host","database","pswd"); 

// Database Connection Check 
if (mysqli_connect_errno($con)) { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    break; 
} 
echo "<table>"; 
echo nextweek("heren1kalender","Heren 1e Provinciale"); 
echo "</table>"; 

function nextweek($table, $ploegNaam) { 
    // Get this weeks dates (monday and sunday and month) 
    $current_day = date("N") 
    $days_to_sunday = 7 - $current_day; 
    $days_from_monday = $current_day - 1; 
    $monday = date("d", strtotime("- {$days_from_monday} Days")); 
    $sunday = date("d", strtotime("+ {$days_to_sunday} Days")); 
    $month = date("m", strtotime("+ {$days_to_sunday} Days")); 

    // SQL query 
    $result = mysqli_query($con,"SELECT datum, hoofd, thuisploeg, bezoekers FROM " . $table . " WHERE thuisploeg LIKE '%Lochristi%' OR bezoekers LIKE '%Lochristi%'"); 

    while($row = mysqli_fetch_array($result)) { 
     $string =""; 
     // Get day and month from array 
     $dag = substr($row['datum'], 4, -6); 
     $maand = substr($row['datum'], 7, -3); 

     if ($dag >= $monday AND $dag <= $sunday AND $maand == $month) { 
      if (strpos($row['thuisploeg'],'Lochristi') !== false) { 
       $string .= "<tr>"; 
       if (substr($row['hoofd'], 0, 1) >= 3) { 
        $string .= '<td class="win">' . $row['hoofd'] . "</td>"; 
       } 
       else { 
        $string .= '<td class="loss">' . $row['hoofd'] . "</td>"; 
       } 
       $string .= '<td>' . $ploegNaam . '</td>'; 
       $string .= "<td><strong>VS</strong></td>"; 
       $string .= '<td>' . $row['bezoekers'] . '</td>'; 
      } 
      elseif (strpos($row['bezoekers'],'Lochristi') !== false) { 
       $string .= "<tr>"; 
       if (substr($row['hoofd'], 0, 1) >= 3) { 
        $string .= '<td class="loss">' . $row['hoofd'] . "</td>"; 
       } 
       else { 
        $string .= '<td class="win">' . $row['hoofd'] . "</td>"; 
       } 
       $string .= '<td>' . $row['thuisploeg'] . '</td>'; 
       $string .= "<td><strong>VS</strong></td>"; 
       $string .= '<td>' . $ploegNaam . '</td>'; 
      } 
      $string .= "</tr>"; 
     } 
    } 
    return $string; 
} 
?> 

而且這些都是PHP錯誤的我越來越:

  1. 警告:mysqli_query()預計參數1是mysqli的,在/home/a2902119/public_html/test.php空給出線24

  2. 警告:mysqli_fetch_array()預計參數1被mysqli_result,在/home/a2902119/public_html/test.php空給出線26

感謝您的幫助!

+0

這意味着您的查詢失敗。現在使用錯誤處理函數並對其失敗的原因進行故障排除。 –

回答

1

您的SQL連接似乎不正確。 它應該有4個部分。

$con=mysqli_connect(hostaddress,dbuser,dbpass,databasename); 
+0

在我的文檔中,它與您提到的文檔相同,我只是對它進行了編輯以供發佈。 –

2

修復其他問題後:變量作用域。 $ con在函數中不可用。將它作爲參數傳遞或返回到類或其他類中。