Here is my snippet of code.  It takes cardnum from the database, removes 
the duplicates for each individual date, and then counts how many discrete 
numbers there was.

<!-- snippet of code starts here -->

//database connect and selection here, now my sql statement:

$sql = "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 '$startdate' and '$enddate' 
group by events.eventime, events.cardnum order by 
convert(varchar,eventime,110), cardnum";

$query = mssql_query($sql);

while ($row = mssql_fetch_assoc($query))
{

$array[$row['date']][] = $row['cardnum'];
}

$i = 0;
$j = 0;

foreach ( $array as $key => $value)
{
echo 'date: '. $key . ', count: ' . count(array_unique($value));
echo "<br>";
$i += count(array_unique($value));
$j++;
}
$query = mssql_query($sql);

while ($row = mssql_fetch_assoc($query))
{

$array[$row['date']][] = $row['cardnum'];
}

$i = 0;
$j = 0;

foreach ( $array as $key => $value)
{
echo 'date: '. $key . ', count: ' . count(array_unique($value));
echo "<br>";
$i += count(array_unique($value));
$j++;
}
echo "total = $i<br>";
echo "average = ".round(($i/$j),1);

<!-- end of code -->

And now my question.  What I need to do is create a single 
dimensional array that contains each number that 
count(array_unique($value)) is counting.  how would I do this?  I can't 
use the SQL query because I have to remove duplicate cardnums for each 
date.

I was thinking of doing:

$patrons = array();

//inside of the foreach have this:
$patrons[] = array_unique($value);

but that doesn't seem to work.  because when I print_r($patrons) its 
creating an array of arrays of an array.  here is from july 1 to july 7th.

date: 07-01-2004, count: 50
date: 07-02-2004, count: 43
date: 07-03-2004, count: 33
date: 07-06-2004, count: 35
date: 07-07-2004, count: 51
Array ( [0] => Array ( [0] => 123 [1] => 204 [2] => 277 [4] => 343 [6] => 
450 [7] => 552 [8] => 637 [9] => 828 [11] => 829 [12] => 1007 [13] => 1075 
[14] => 1363 [15] => 1455 [17] => 1539 [18] => 1736 [19] => 1928 [23] => 
1929 [25] => 2044 [26] => 2221 [29] => 2222 [34] => 2961 [36] => 2969 [37] 
=> 3122 [39] => 3273 [42] => 3274 [46] => 3286 [47] => 3288 [51] => 3294 
[52] => 3322 [53] => 3325 [54] => 3326 [56] => 3327 [57] => 3328 [59] => 
3329 [60] => 3330 [61] => 3332 [62] => 3333 [63] => 3334 [64] => 3335 [65] 
=> 3336 [66] => 3337 [68] => 3338 [69] => 3339 [70] => 3340 [71] => 3341 
[72] => 3342 [73] => 3343 [74] => 3344 [76] => 3345 [77] => 3346 ) [1] => 
Array ( [0] => 114 [1] => 123 [2] => 277 [3] => 369 [5] => 637 [6] => 744 
[7] => 829 [8] => 1264 [10] => 1702 [11] => 1738 [13] => 1911 [15] => 1928 
[20] => 2221 [24] => 2222 [29] => 2593 [30] => 2961 [31] => 2969 [34] => 
3037 [35] => 3273 [38] => 3274 [43] => 3322 [45] => 3336 [46] => 3338 [48] 
=> 3347 [50] => 3348 [53] => 3349 [55] => 3350 [56] => 3351 [57] => 3352 
[59] => 3353 [61] => 3354 [62] => 3355 [63] => 3356 [66] => 3357 [68] => 
3358 [69] => 3359 [70] => 3360 [71] => 3361 [72] => 3362 [73] => 3363 [75] 
=> 3364 [76] => 3365 [77] => 3366 ) [2] => Array ( [0] => 87 [2] => 344 
[3] => 355 [4] => 362 [5] => 637 [7] => 744 [8] => 825 [9] => 826 [11] => 
895 [13] => 1478 [15] => 1654 [17] => 2429 [18] => 2654 [20] => 2756 [21] 
=> 2969 [22] => 3124 [23] => 3166 [24] => 3273 [27] => 3274 [29] => 3294 
[31] => 3351 [32] => 3352 [34] => 3361 [36] => 3367 [37] => 3368 [39] => 
3369 [40] => 3370 [42] => 3372 [43] => 3373 [44] => 3374 [45] => 3375 [46] 
=> 3376 [47] => 3378 ) [3] => Array ( [0] => 314 [4] => 343 [7] => 637 [8] 
=> 825 [9] => 826 [10] => 829 [11] => 1736 [13] => 1844 [15] => 2084 [17] 
=> 2967 [18] => 2990 [19] => 2991 [21] => 3037 [23] => 3078 [24] => 3106 
[25] => 3107 [28] => 3179 [31] => 3379 [34] => 3380 [36] => 3381 [38] => 
3382 [40] => 3383 [41] => 3384 [42] => 3385 [44] => 3386 [45] => 3387 [46] 
=> 3388 [47] => 3389 [48] => 3390 [49] => 3391 [51] => 3392 [53] => 3393 
[54] => 3394 [55] => 3395 [56] => 3396 ) [4] => Array ( [0] => 63 [3] => 
203 [4] => 286 [5] => 637 [7] => 828 [9] => 829 [10] => 1066 [12] => 1262 
[13] => 1702 [14] => 1736 [16] => 1738 [17] => 1844 [19] => 1926 [20] => 
2654 [23] => 2946 [24] => 2990 [26] => 2991 [29] => 3179 [31] => 3220 [33] 
=> 3286 [35] => 3316 [38] => 3334 [39] => 3361 [41] => 3383 [43] => 3384 
[44] => 3385 [45] => 3390 [46] => 3391 [48] => 3398 [49] => 3399 [50] => 
3400 [53] => 3401 [55] => 3402 [59] => 3403 [63] => 3404 [65] => 3405 [71] 
=> 3406 [72] => 3407 [73] => 3408 [74] => 3409 [75] => 3410 [76] => 3411 
[77] => 3412 [79] => 3413 [81] => 3414 [82] => 3415 [83] => 3416 [84] => 
3418 [85] => 3419 [86] => 3420 [87] => 3421 ) ) total = 212
average = 42.4 

note that there is no july 4th and 5th because we were closed those days.

what I want to do is is say after I add the first array of dates into 
$patrons[], say if its 10 cardnums, i'll have $patrons[0] through $patrons[9], 
and when I add the next day and it was 8 cardnums, it would be 
$patrons[10] through $patrons[17].  but instead its creating 
$patrons[0][0] through patrons[0][9] and next day is $patrons[1][0] 
through $patrons[1][7].  atleast thats what I think is happening.

so how do I get it to just put all of the card nums that 
count(array_unique($value)) is counting into a single dimensional array?  
thanks

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to