EDIT:: Maybe I should be asking what the proper way to get a result set from the database is. When you have 5 joins where there is a 1:M relationship, do you go to the database 5 different times for the data??
Ben yaklaşık bir saat önce bu soruyu sordum ama uydurma bir cevap almak mümkün olmamıştır. Ben önde gitti ve tam olarak neye ihtiyacım yok bazı kodlar yazdım ama bunu yapmak için daha iyi bir yol arıyorum
Bu dizi bana sadece bazı kez ihtiyaç vardır ve diğerleri birçok kez gerekli olan birden çok satır verir. Ben aşağıda yaptığım gibi bu filtre gerekir ama mümkünse bunu yapmanın daha iyi bir yol istiyoruz.
Array
(
[0] => Array
(
[cid] => one line
[model] => one line
[mfgr] => one line
[color] => one line
[orderid] => one line
[product] => many lines
[location] => many lines
)
[1] => Array
(
.. repeats for as many rows as were found
)
)
Bu kod mükemmel ama yine çalışıyor, ben bunu yapmanın daha etkili bir yolu olduğunu düşünüyorum. Bana biraz bu kadar temiz sağlayacak bir PHP işlevi var mı?
// these are the two columns that produce more than 1 result.
$product = '';
$orderid = '';
foreach($res as $key)
{
// these produce many results but I only need one.
$cid = $key['cid'];
$model = $key['model'];
$mfgr = $key['mfgr'];
$color = $key['color'];
$orderid = $key['orderid'];
// these are the two columns that produce more than 1 result.
if($key['flag'] == 'product')
{
$product .= $key['content'];
}
if($key['flag'] == 'orderid')
{
$orderid .= $key['content'];
}
}
// my variables from above in string format:
Burada talep edilen bir SQL
SELECT
cid,
model,
mfgr,
color,
orderid,
product,
flag
FROM products Inner Join bluas ON products.cid = bluas.cid
WHERE bluas.cid = 332
ORDER BY bluas.location ASC