Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用存储在数组中的php从MySql数据库中分别获取所有匹配记录?_Php_Mysql - Fatal编程技术网

如何使用存储在数组中的php从MySql数据库中分别获取所有匹配记录?

如何使用存储在数组中的php从MySql数据库中分别获取所有匹配记录?,php,mysql,Php,Mysql,我有一个超过1400行的MySql数据库。使用sql查询,我得到匹配的行并将它们存储在一个数组中。我想做的是,所有存储的值都显示在我的网站上 文件名为filter.php $sql = "SELECT * FROM champ where GG IS NULL OR GG= ' ' AND K=' ' AND J=' '"; $result = $conn->query($sql); $array = array(); if ($result->num_rows > 0)

我有一个超过1400行的MySql数据库。使用sql查询,我得到匹配的行并将它们存储在一个数组中。我想做的是,所有存储的值都显示在我的网站上

文件名为filter.php

$sql = "SELECT * FROM champ where GG IS NULL OR GG= ' ' AND  K=' ' AND  J=' '";
$result = $conn->query($sql);
$array = array();
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
$array[] = $row; 
}

for($i = 0, $j = count($array); $i < $j ; $i++){

 $HomeTeam = $array[$i]['HOME'];
 $AwayTeam =   $array[$i]['AWAY'];
}

} else {
    echo "0 results";
}
$conn->close();
?> 
$sql=“从champ中选择*,其中GG为NULL或GG=''、K=''和J='';
$result=$conn->query($sql);
$array=array();
如果($result->num_rows>0){
//每行的输出数据
而($row=$result->fetch_assoc()){
$array[]=$row;
}
对于($i=0,$j=count($array);$i<$j;$i++){
$HomeTeam=$array[$i]['HOME'];
$AwayTeam=$array[$i]['AWAY'];
}
}否则{
回显“0结果”;
}
$conn->close();
?> 
我想在我的网站上使用这些数据,我试过这个代码

<table class="table">   
<thead> 
      <tr>
        <th>Home Team</th>
    <th>Away Team</th>
      </tr>
</thead>
<tr>
<?php
include 'filter.php';
echo"<td>". $HomeTeam."</td>";
echo"<td>".$AwayTeam."</td>";
echo "</tr>";
?>
</table>

主队
客队
我做错了什么?因为这只给了我最后的记录值。
如果有人能帮助我,我将非常高兴。谢谢。

首先,您需要在sql中用括号括起OR条件

然后在while循环中简单地处理结果集,并在运行时从查询中输出数据

$sql = "SELECT * 
        FROM champ 
        where (GG IS NULL OR GG= ' ')
        AND  K=' ' AND  J=' '";

$result = $conn->query($sql);

$champs = array();
while ( $row = $result->fetch_assoc() ) {
    $champs[] = $row;
}
?> 

<table class="table">   
<thead> 
    <tr>
        <th>Home Team</th>
        <th>Away Team</th>
    </tr>
</thead>
<tbody>
<?php 
foreach ($champs as $champ ) :
?>
    <tr>
        <td><?php echo $champ['HOME'];?></td>
        <td><?php echo $champ['AWAY'];?></td>
    </tr>
<?php
endforeach;
?>
</tbody>
</table>
$sql=“选择*
来自冠军
其中(GG为NULL或GG='')
K=''和J='';
$result=$conn->query($sql);
$champs=array();
而($row=$result->fetch_assoc()){
$champs[]=$row;
}
?> 
主队
客队

谢谢您的回答,我应该使用数组中的数据,因为我在数组中的表中存储了更多我以后要使用的数据。你能给我一个建议吗?怎么样,这就是你需要的吗