182x Posted July 28, 2007 Share Posted July 28, 2007 Hey guys,, just wondering where I went wrong with this code, I am trying to ensure that the an array only gets filled with 1 year and the total times that year appears in both tables but the problem is that data is only being supplied once from the second table. Just wondering how to fix this? Thanks. $getAll = "SELECT year, count(*) FROM test1 GROUP BY year"; $queryAll = mysql_query($getAll, $link_id) or die(mysql_error()); $getAll2 = "SELECT year, count(*) FROM test2 GROUP BY year"; $queryAll2 = mysql_query($getAll2, $link_id) or die(mysql_error()); $rowAll3[4]; while($rowAll = mysql_fetch_array($queryAll) && $rowAll2 = mysql_fetch_array($queryAll2)) { if ($rowAll['year'] == $rowAll2['year']) { $rowAll3[1] =$rowAll['year']; $rowAll3[0] =$rowAll['count(*)']+$rowAll2['count(*)']; } if ($rowAll['year'] != $rowAll2['year']) { $rowAll3[1] =$rowAll['year']; $rowAll3[0] =$rowAll['count(*)']; } if ($rowAll2['year'] != $rowAll['year']) { $rowAll3[1] =$rowAll2['year']; $rowAll3[0] =$rowAll2['count(*)']; } $amountAll[] = $rowAll3[0]; $yearAll[] = $rowAll3[1]; printf("<pre>%s</pre>\n", print_r($rowAll3, 1)); } Quote Link to comment Share on other sites More sharing options...
fenway Posted July 31, 2007 Share Posted July 31, 2007 I'm not really sure what you're trying to do... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.