2013-10-08 50 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在函数中不可用。将它作为参数传递或返回到类或其他类中。