Jump to content

Logic error


182x

Recommended Posts

hey guys, trying to make the following code work but there is a problem with the while just wondering how to fix that so that the year will be stored just once and with the total amount of times it appears in each table?

 

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/62197-logic-error/
Share on other sites

$query = "SELECT DISTINCT t1.year,t2.year,count(*) FROM test1 AS t1,test2 AS t2 GROUP BY t1.year,t2.year";
$res = mysql_query($query);
while($row = mysql_fetch_array($res)){
print_r($res);
}

 

prehaps try debugging with this by viewing the results of the query.

Link to comment
https://forums.phpfreaks.com/topic/62197-logic-error/#findComment-309592
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.