Hi all.
I am trying to count the number of rows from multiple tables in a single query based on criteria. For example, say I have 2 tables, books & bags but based on certain type of a book & certain type of a bag. Now I want to count the number of rows in books table & the number of rows in bags table, all in the same query. I tried some queries like the following:


PHP Code:
$sql    "SELECT  count(*) FROM $books AS books_rows, (SELECT  count(*) FROM $bags AS bags_rows) WHERE books_rows.book_id = '$book_id' AND bags_rows.bag_id = '$bag_id' AND bags_rows.available = 'y'  AND (bags_rows.in_stock = 'y' OR bags_rows.color_available = 'y' OR bags_rows.sold_out = 'n') GROUP BY books_rows.on_id, bags_rows.post_id ";

$result          mysql_query($sql) ;

// I tried different ways of query, like:
$rows mysql_fetch_array($result);
 
$sql_data mysql_fetch_row($result); 

Nothing really seems to get me the count from the 2 tables in the same query depending on the criteria. Can some one please suggest a solution?

Thank you in advance.