Ben bir üst kategori altındaki tüm kategoriler kapmak şu var:
<?php
$childrows = array();
$result2 = mysql_query("SELECT * FROM categories WHERE category_parent_id='$cid'"); while
($row = mysql_fetch_array($result2)){
$childrows [] = $row['category_id'];
print_r($childrows); }
?>
Bu döndürür:
Array ( [0] => 47 ) Array ( [0] => 47 [1] => 48 ) Array ( [0] => 47 [1] => 48 [2] => 63 ) Array ( [0] => 47 [1] => 48 [2] => 63 [3] => 64 ) Array ( [0] => 47 [1] => 48 [2] => 63 [3] => 64 [4] => 68 ) Array ( [0] => 47 [1] => 48 [2] => 63 [3] => 64 [4] => 68 [5] => 69 )
Olan sorun im ben ürünler tablosundan dizide saklanan kategoride (category_id) kapsamındaki ürünlerin sayısını (product_id) saymak gerekir, bir sonraki aşamasıdır.
Bir yolu olmalı!?
Thanks for looking. B.
Tam kodu:
<?php
if ($num_rows == 0) {
$result2 = mysql_query("SELECT * FROM categories WHERE category_parent_id='$cid'");
while ($row = mysql_fetch_array($result2)){
$childrows [] = $row['category_id'];
}
$category_string = implode(",",$childrows);
$result3 = mysql_query("SELECT category_id, COUNT(product_id)
FROM products
WHERE category_id IN ($in_string)");
$result3 = mysql_fetch_array($result3);
$result3 = $result3[1];
echo $result3;
}
else {
echo $num_rows;
}
?>
ama bu sadece reurns:
Notice: Undefined variable: hattına 31 (WHERE category_id IN ($ in_string) ") üzerine in_string ;)
Warning: mysql_fetch_array (): Verilen argüman hattı 32 geçerli MySQL result resource ($ result3 = mysql_fetch_array ($ result3) değil ;)