mysql_connect("localhost", "root", "");
$dbname = "databased";
//model all 1006 record in warranty_items;
//model all 284131 record in warranty_product_registrations;
$modelname1_1 = "select model from warranty_items group by model order by model asc";
$modelname1_2 = mysql_db_query($dbname, $modelname1_1);
while ($modelname1_3 = mysql_fetch_array($modelname1_2)) {
$modelname2_1 = "select count(model) as md from warranty_product_registrations where model='".$modelname1_3['model']."' and model<>''";
$modelname2_2 = mysql_db_query($dbname, $modelname2_1);
$modelname2_3 = mysql_fetch_array($modelname2_2);
echo $modelname1_3['model']." = ".$modelname2_3['md']."<br />";
}
$modelname1_1 = "
SELECT a.model, coalesce( b.c, 0 ) md
FROM (
SELECT DISTINCT model FROM warranty_items
) a
LEFT JOIN (
SELECT model, count(*) c
FROM warranty_product1_registrations
GROUP BY model
)b ON b.model = a.model
ORDER BY model
";
$modelname1_2 = mysql_db_query($dbname, $modelname1_1);
while ($modelname1_3 = mysql_fetch_assoc($modelname1_2)) {
echo $modelname1_3['model']." = ".$modelname2_3['md']."<br />";
}