我有这张桌子
Column_1 Column_2
1 value1
2 value1
3 value2
我的php查询
$query = "SELECT * FROM `table` WHERE `Column_1` = 'value1' ";
print_r($query);
这只返回第1行。我希望显示第1行和第2行。当我在phpmyadmin中运行SQL时,它返回第1行和第2行。但是,php脚本只返回第1行......我也做了
echo count($query);
但它只返回1.我做错了什么?
答案 0 :(得分:2)
$query = "SELECT * FROM `table` WHERE `Column_2` = 'value1' ";
$res = mysql_query($query);
if(mysql_num_rows($res)!=0) {
while($rowData = mysql_fetch_array($res)) {
var_dump($rowData);
}
}
答案 1 :(得分:1)
$query = "SELECT * FROM `table` WHERE `Column_1` = 'value1' ";
$res = mysql_query($query);
while($row = mysql_fetch_assoc())
print_r($row);
您需要在周期中添加提取。
答案 2 :(得分:0)
Use mysql_fetch_array() function
$query = "SELECT * FROM `table` WHERE `Column_1` = 'value1' ";
$res = mysql_query($query);
while($row = mysql_fetch_array($res))
{
echo $row['Column_1'];
echo $row['value_1'];
}