为什么我无法在MySQL中获得不同行的结果?

时间:2013-12-31 11:09:00

标签: php mysql

当我在我的网站上在MySQL中进行查询时,只有在表格中有多个相同的行时才显示条目

+-----+-----+-----+-----+  
| pid | uid | lpa | lar |  
+-----+-----+-----+-----+    
|  1  |  1  | AA  | BB  |  
|  2  |  1  | CC  | CC  |  
|  3  |  1  | AA  | AA  |  
|  4  |  1  | AA  | AA  |  
|  5  |  1  | DD  | EE  |
|  6  |  1  | CC  | CC  |
|  7  |  1  | AA  | CC  |
|  8  |  1  | FF  | FF  |
|  9  |  1  | AA  | BB  |  
+-----+-----+-----+-----+  



$query0 = mysqli_query($con, "
SELECT pid, uid, lpa, lar
FROM table
WHERE lpa = 'AA' AND lar = 'BB'"); 
$row = mysqli_fetch_array($query0); 
mysqli_close($con);  
while($row=mysqli_fetch_array($query0)) { 
echo "
<tr>
<td>" . $row['pid'] . "<br></td>
<td>" . $row['uid'] . "<br></td>
<td>" . $row['lpa'] . "<br></td>
<td>" . $row['lar'] . "<br></td>
</tr>
"; 
}
在WHERE子句中

如果表中有两个相同的行,我可以得到结果,否则结果表是空的!

编辑:对不起,我已经使用了顶点,我只是忘了在这里写。

3 个答案:

答案 0 :(得分:3)

试试这个

SELECT pid, uid, lpa, lar
FROM table
WHERE lpa = 'AA' AND lar = 'BB'"

你应该引用字符串..如果是整数或浮点数......那么

答案 1 :(得分:0)

$query0 = mysqli_query($con, "
SELECT pid, uid, lpa, lar
FROM table
WHERE lpa = 'AA' AND lar ='BB'"); 

答案 2 :(得分:0)

我认为以下代码中的标记此处 mysqli_fetch_array()应该被删除。

$query0 = mysqli_query($con, " SELECT pid, uid, lpa, lar FROM table WHERE lpa = 'AA' AND lar = 'BB'"); 

$row = mysqli_fetch_array($query0); 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <= "Here"

mysqli_close($con);  

while($row=mysqli_fetch_array($query0)) 
{ 
    echo "
    <tr>
    <td>" . $row['pid'] . "<br></td>
    <td>" . $row['uid'] . "<br></td>
    <td>" . $row['lpa'] . "<br></td>
    <td>" . $row['lar'] . "<br></td>
    </tr>
    "; 
}