This worked wonderfully. Thanks, Dash.
----- Original Message -----
From: "Dash McElroy" <[EMAIL PROTECTED]>
Subject: Re: [PHP-WIN] arrays and nested arrays and loops and databases...
> If I understand correctly, you want to have an array containing an array
> with people's email address and name from your db like this:
>
> $to[0]['address'] = [EMAIL PROTECTED]
> $to[0]['name'] = Bob Smith
> $to[1]['address'] = [EMAIL PROTECTED]
> $to[1]['name'] = John Jones
>
> (the above is obviously not valid PHP...)
>
> I would do something like this:
>
> $to = array();
> $query = "select email, fullname from tablename where updateannounce = 1";
> $result = mysql_query($query);
> while ($output = mysql_fetch_array($result)) {
> $to[] = array('address' => $output['address'],
> 'name' => $output['name']);
> }
>
> assuming, of course, that your database column names are 'address' and
> 'name'.
>
> This should work, but I may have borked something up on the name based
> arrays.
>
> -Dash
> On Sat, 18 Jan 2003, H Marc Bower wrote:
>
> > Well... I can usually puzzle myself through these things, but I figured
> > it's time to ask the list. :) It may be a simple thing that I'm
missing,
> > but here's what I have.
> >
> > The structure that I'm trying to modify is as follows:
> >
> > $to = array(
> > array(
> > 'address'=>'[EMAIL PROTECTED]',
> > 'name'=>'Bob Smith'
> > ),
> > array(
> > 'address'=>'[EMAIL PROTECTED]',
> > 'name'=>'John Jones'
> > )
> > );
> >
> > That said, I have a database of names and email addresses which I want
to
> > insert into this structure, but in a loop since I don't want to have an
> > array() section for each one, not knowing how many are going to be in
the
> > list at the time this script is run. I want to loop the 'sub' array()
> > statements so that I can build up the main array(). I use mysql as
follows:
> >
> > $query = "select email, fullname from tablename where updateannounce =
1";
> > $result = mysql_query($query);
> > while ($output = mysql_fetch_array($result))
> > {
> > //This is where I want the loop of arrays to appear, so I can
> > dynamically insert the email and fullname fields into the obvious spots
> > }
> >
> >
> > I need to figure out how to do this, essentially:
> >
> > $to = array(<loop to fill other array() statements>);
> >
> > I don't know how to get that loop to work inside the overall array()
> > statement, though... any assistance would be greatly appreciated.
> >
> > Thank you,
> >
> > Marc
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php