我试图只选择购物车中的项目,但我的查询返回产品表中的所有项目。我不知道我的问题出在哪里有人能帮我存档吗?
管理员
id | adminpkey | Aname
-----|-----------|---------
1 | adKM10 | peter
项目
id | IDitem | keyAdmin | Iname | type
-----|---------|----------|-------|-------
1 | a100 | adKM10 | car | AA
2 | a200 | adKM10 | house | KM
3 | a300 | adKM10 | house | KD
运货马车
cid | cartID | itemID | buyerId | qty
-----|---------|----------|-----------|---------
1 | cart100 | a100 | 100 | 3
SQL查询
SELECT * FROM cart c
INNER JOIN item i
ON c.itemID = i.IDitem
INNER JOIN admin a
ON a.adminpkey = i.keyAdmin
WHERE c.buyerId = 100'
PHP代码
<?php
$setcartdata = array();
foreach($cartarraymarge as $data){
$setcartdata['item_'.$data->IDitem.'_'.$data->cartID]['name'] = $data->Iname;
$setcartdata['item_'.$data->IDitem.'_'.$data->cartID]['type'] = $data->type;
}
var_export($setcartdata);
exit();
结果
array (
'item_a100_cart100' =>
array (
'name' => 'car',
'type' => 'AA',
'qty' => 3
),
'item_a200_cart100' =>
array (
'name' => 'house',
'type' => 'KM',
'qty' => 3
),
'item_a300_cart100' =>
array (
'name' => 'house',
'type' => 'KD',
'qty' => 3
),
)
暂无答案!
目前还没有任何答案,快来回答吧!