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 14:13
Till: Jonas Rosling
Kopia: PHP List
Ämne: Re:  One works, but the other doesn't


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'];
        }
}

-------------------------
Well, I'm kind of a newbie at this. So you think this will solve my problem?

Look at it this way - Which one is easier to read? Which one do you
think will be easier to work out what's going wrong?

Readability of your code will help you so much. If you come back to
this in a week, will you understand what's going on?

I don't know if my code will give you *exactly* what you want - test
it and see (backup your existing php file, change this code, see what
you get).

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