Re: One works, but the other doesn't

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/23/06, Jonas Rosling <webmaster@xxxxxxxxxxxx> wrote:
-----Ursprungligt meddelande-----
Från: chris smith [mailto:dmagick@xxxxxxxxx]
Skickat: den 23 maj 2006 13:38
Till: Jonas Rosling
Kopia: PHP List
Ämne: Re:  One works, but the other doesn't


On 5/23/06, Jonas Rosling <webmaster@xxxxxxxxxxxx> wrote:
> I find this problem very strange. I've got two parts of code (allmost the
> same) in different TD's with vars and arrays (with same name) but it's
only
> the top code that gives result. I've allso tryied to rename the vars and
> TD's in the bottom without any luck. The only vars/arrays that I haven't
> mind changing name on yet are some dynamic, like:
>
>         ${$row[0]} = array();
>
>         ${$row[0]}[$row[1]] = $row[2];
>
> But I think this could be the main cause, but I'm not really sure. If I
> delete the top code the bottom works. Any idéas any one?

Without seeing the whole code involved, my guess is you're resetting
the array with every loop.

Guesses don't help but that's all we can do without seeing any actual code.

Okej, all the code follows bellow. Remember that part 1 allways works. And
they work all seperatly.

Man you do things the hard way. Why use all those variable variables?


$my_data = array();

// Loppar igenom raderna
while($row=mysql_fetch_assoc($result)) {
	$code = $row['salesperson_code'];

	if (!isset($my_data[$code])) {
		$my_data[$code] = array(
			'description' => $row['description'],
			'total' => $row['totalt'],
			'antal' => $row['antal']
		);
	} else {
		$my_data[$code]['description'] = $row['description'];
	}
}

var_dump($my_data);

MUCH easier to read and you'll find debugging LOTS easier.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux