坚持使用SQL查询中的项目创建数组

时间:2015-08-14 09:46:33

标签: php sql arrays while-loop

基本上我不会能够抓住所有项目并将它们插入数组中,此时我已经制作了类别数组,但我似乎无法获得数组中的所有项目只有一个项目进入每个部分

$sql2 = "SELECT * FROM products group by Market ";
$result2 = $conn->query($sql2);

// GETS all Category
$sql = "SELECT DISTINCT Category FROM products group by Category";

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

$array = array();

while ($row = $result->fetch_assoc()) {

    $array[$row['Category']] =  array();
}

while ($row = $result2->fetch_assoc()) {

    $array[$row['Category']] =  array($row['Market']);
}

目前输出

array of my categories with one item

但是每个类别都有更多的项目,例如,看看SQL有2个摄像机市场,在我看来它不是循环所有子类别或覆盖它们

SELECT * FROM products where Category = 'CAMCORDERS' group by Market 

query of camcorders

0 个答案:

没有答案