Re: assignment of data into a 2 dimensional array
| From: | John W. Holmes | Date: | Mon, 03 May 2004 19:04:13 +0000 |
| Subject: | Re: assignment of data into a 2 dimensional array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185233@lists.php.net to get a copy of this message | ||
From: "Adam Williams" <awilliam@mdah.state.ms.us>
> Hi, I am querying a MSSQL server with the query statement:
>
> select convert(varchar, eventime, 110) as date, cardnum from events,
> badge, where eventtype = 0 and devid = 1 and events.cardnum=badge.id and
> badge.type = 1 and convert(varchar,eventime,110) between '04-20-2004' and
> '04-21-2004' group by events.eventime, events.cardnum order by
> convert(varchar,eventime,110)
>
> and a snippet of the result is:
>
> date cardnum
> 04-20-2004 2379
> 04-20-2004 2380
> 04-21-2004 1828
> 04-21-2004 1203
[snip]
> the final array should look like:
>
> array[x][x]:
>
> 04-20-2004 -> 2379
> 2380
> 296
> 314
> 2396
> 2395
>
> 04-21-2004 -> 2398
> 1403
> 1736
> 1828
> 1203
while($row = mssql_fetch_array($result))
{
$array[$row['date']][] = $row['cardnum'];
}
??
That should produce something like
Array ( '04-20-2004' => array(2379,2380,296,314,2396,2395), '04-21-2004'
=>
array(2398,1403,1736,1828,1203))
count($array['04-21-2004']) will tell you how many "cardnum"s are assigned
to that date.
foreach($array['04-21-2004'] as $cardnum)
{ echo $cardnum; }
will allow you to loop through each date and print the cardnums associated
with it...
Post back if that's not what you're after.
---John Holmes...