Php 在查询后从数组中获取正确的数据?
我有一个sql语句Php 在查询后从数组中获取正确的数据?,php,mysql,database,Php,Mysql,Database,我有一个sql语句 "SELECT o.orderID, p.productID, p.name, o.qty, p.mouldID FROM products AS p INNER JOIN orderedProducts AS o ON o.productID = p.productID WHERE o.orderID = '$id'"; 当我在phpmyadmin中使用它来测试它时,它看起来是这样的(我使用ID56) 但吐出的数组是: Array ( [0] => 56 [orde
"SELECT o.orderID, p.productID, p.name, o.qty, p.mouldID FROM products AS p INNER JOIN orderedProducts AS o ON o.productID = p.productID WHERE o.orderID = '$id'";
当我在phpmyadmin中使用它来测试它时,它看起来是这样的(我使用ID56)
但吐出的数组是:
Array ( [0] => 56 [orderID] => 56 [1] => 11 [productID] => 11 [2] => newproduct [name] => newproduct [3] => 2000 [qty] => 2000 [4] => 4 [mouldID] => 4 )
这不是我想要的数据,所以我试着看看如果我把它放到一个表中会发生什么
它回来了
0 | 56
orderID | 56
1 | 11
productID | 11
2 | newproduct
name | newproduct
3 | 2000
qty | 2000
4 | 4
mouldID | 4
显然出了点问题
我使用
mysql\u fetch\u array
将数据从数据库中获取到数组中……这可能是我做错的吗
基本上,我希望它看起来像数据库返回的第一个表
任何想法…谢谢 mysql\u fetch\u XXX()函数只返回下一行,而不是所有结果。如果需要一个包含所有行的数组,则必须使用循环来构造它:
while ($row = mysql_fetch_assoc($query)) {
$results[] = $row;
}
var_dump($results);
mysql\u fetch\u array()
一次只返回一行。你必须在循环中调用它来获取所有数据。
while ($row = mysql_fetch_assoc($query)) {
$results[] = $row;
}
var_dump($results);