Using Array In Sql Query?

Advertisement

I have the following that grabs all the categories under a parent category:

<?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); }
?>

This returns:

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 )

The problem im having is the next stage, I need to count the number of products(product_id) under the categories(category_id) stored in the array from the products table.

[Code]....

but this just reurns:

Notice: Undefined variable: in_string in on line 31(WHERE category_id IN ($in_string)");)

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 32 ($result3 = mysql_fetch_array($result3);)