Jump to content

mysql logic help


182x

Recommended Posts

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

}

Link to comment
https://forums.phpfreaks.com/topic/62190-mysql-logic-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.