嘿所有我想知道如何从表中获取所有查询,它只获得第一个并停止
我的代码:
$result1 = mysql_query("SELECT `to` FROM transactions WHERE `from` = '$user'");
$row = mysql_fetch_row($result1);
$result2 = mysql_query("SELECT `amount` FROM transactions WHERE `from` = '$user'");
$row2 = mysql_fetch_row($result2);
echo "<li>TO</li>";
echo "<li>AMOUNT</li>";
echo "<li>$row[0]</li>";
echo "<li>$row2[0]</li>";
echo "<li>$row[1]</li>";
echo "<li>$row2[1]</li>";
echo "<li>$row[2]</li>";
echo "<li>$row2[2]</li>";
echo "<li>$row[3]</li>";
echo "<li>$row2[4]</li>";
echo "<li>$row[4]</li>";
echo "<li>$row2[5]</li>";
我的数据库:
答案 0 :(得分:1)
$row = mysql_fetch_row($result1); will only fetch one row
您需要使用while
$query = mysql_query("SELECT `to`, `amount` FROM transactions WHERE `from` = '$user'");
echo "<li>TO</li>";
echo "<li>AMOUNT</li>";
while ($row = mysql_fetch_assoc($query)) {
echo "<li>{$row['to']}</li>";
echo "<li>{$row['amount']}</li>";
}