Re: Beginner Help - Array
| From: | chris smith | Date: | Fri, 14 Apr 2006 00:10:55 +0000 |
| Subject: | Re: Beginner Help - Array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233960@lists.php.net to get a copy of this message | ||
On 4/14/06, P. Guethlein <peterg@deltronix.com> wrote:
> This seems like it should work, but the option statement is just
> filling in one line of data....hmmmmm... the names have multiple
> territories (ID's), so I want to have one name associated with one
> territory ID ( other stuff happens elseware...).
>
> //building list of names and their territory matching ID's
> while($getidsd = mysql_fetch_array($getidsr)){
> if ($getidsd['employeeid'] != '990'&&
> $getidsd['employeeid'] != '991') {
> $salespersonsstor=
> Array("name"=>$getidsd['fname'].'
> '.$getidsd['lname'],"idIS"=>$getidsd['employeeid']);
> }
> }
You're always overwriting the array here. PHP arrays can't have
duplicate keys, so it's doing:
name -> $getidsd['fname'];
next time it gets a row, it's overwriting it.
If you do something like this:
$salespersonsstor[] = Array("name"=>$getidsd['fname'].'
'.$getidsd['lname'],"idIS"=>$getidsd['employeeid']);
it will add to the array (notice the square brackets).
Do a print_r or var_dump after your loop so you understand how the
array is put together and how you can then use it.
--
Postgresql & php tutorials
http://www.designmagick.com/