0

i want to call from an array using the get array but it doesn't work what is the correct way to format this?

if(isset($_GET["category"])){
    $cat = 'SELECT DISTINCT `Category` FROM `products`';
    $result = $mysqli->query($cat);
    $i='0';
    while ($row = $result->fetch_array(MYSQLI_ASSOC)){
        $i++;
        $Category = $row["Category"];
        $id = array($i => $Category);
    }
    $result->close();
    $query = 'SELECT * FROM products WHERE Category="'. $id[$_GET["category"]]. '" ORDER BY Code';
}
4

2 回答 2

1

看来,您在循环中犯了一个错误。如果要为数组键分配值,则需要替换:

$id = array($i => $Category);

有了这个:

$id[$i] = $Category;

否则$id将始终是仅具有当前键值对的新数组。

于 2012-07-02T14:04:15.650 回答
0

你的查询是错误的。利用

$query = "SELECT * FROM products WHERE Category='". $id[$_GET["category"]]. "' ORDER BY Code";

order by子句必须在子句之后where

于 2012-07-02T13:57:57.990 回答