Re: assignment of data into a 2 dimensional array

From: Date: Mon, 03 May 2004 18:52:45 +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-185231@lists.php.net to get a copy of this message
On Mon, 3 May 2004, John W. Holmes wrote: > Can you give an example of where this data is coming from and how its > formatted before you want to reformat it? Is the list and date the result of > a query or do you have the list in a separate variable or array? > > $list1 = '2,3,4,5'; > $list2 = '6,3,5,6,7'; > > How do those relate to the dates? Are you running multiple queries? A short > code example would help us a lot here. > > ---John Holmes... > > 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-20-2004 296 04-20-2004 314 04-20-2004 2396 04-20-2004 2395 04-21-2004 2398 04-21-2004 2398 04-21-2004 1403 04-21-2004 1736 04-21-2004 1828 04-21-2004 1203 This data is being entered through a proprietary piece of software that interfaces with a MSSQL server. Each visitor is an ID card with a unique cardnum. They swipe their card into a card reader and the proprietary software records the time of their visit and their cardnum into the database. My boss wants to be able to enter a user selectable range of dates (which is easy to do, just change the start and end dates of the select statement to variables) but I need to somehow put the dates and their corresponding cardnum's into an array so that I can loop through the array to count the number of discrete visits by each cardnum. What I am saying is that we just want to know if a person came to the building at all that day, not how many times they came to visit in a day, so we just need to know if their cardnum exists atleast once for that day. For example, the person has to exit through the enterance to get to the bathrooms/coke machines (They are in the lobby outside of the card swipe) so they have to re-swipe their card to be let back in, this is why we don't want to know how many times they've visited on a day, just if they have visited at all or not. So my boss wants a total count of the discrete visits, broken down by date. but, I'm not sure how to put all of the dates and their discrete cardnum's into a 2 dimentional array, and then how to count the discrete cardnum's by the date. I know I'll need a loop to put the data into an array that will look like: while ($row = mssql_fetch_array($query)) { //figure out how to put distinct dates and their matching discrete numbers //into a 2 dimensional array } but I'm completely lost as to what code I should use, because I'll need something that loops through the array to check if the date is in the array and if not, make the next available array[x] hold that date, and also check if a number has been used with its corresponding date, and if so do nothing, if the number isn't used in the array with its corresponding date to add it to the array, so that I can then count the total number of discrete cards on a date. 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

« previous php.general (#185231) next »