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
Share on other sites

That won't work as I am dealing with data from both tables and need the total of all the year amount but only keep one of the actual year values for example one table could have 2007, 50, 2007, 50 and the other table could have 2007, 10, 2007, 10. So i need just 2007, 120.

Link to comment
Share on other sites

Sorry maybe I am not being clear I have to be able to count the number of time the years occur from 2 different and unrelated tables and store this information in an array but I only want the actual year value to be stored once along the number of times that year occurs.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.