RE: [PHP-DB] array_diff usage

From: Date: Mon, 02 Apr 2001 15:59:13 +0000
Subject: RE: [PHP-DB] array_diff usage
Groups: php.db 
Request: Send a blank email to php-db+get-8144@lists.php.net to get a copy of this message
> -----Original Message----- > From: Martin [mailto:chimbis@skjoldebrand.org] > Sent: Monday, April 02, 2001 10:48 AM > To: Mark Roedel; php-db@lists.php.net > Subject: RE: [PHP-DB] array_diff usage > > > >> This, on the other hand, makes me suspect that the arrays themselves >> don't actually contain what you think they do. How are you >> assigning the values you described at the top of your message? > > I get them from a database by two select queries. > Then I do > > $noOpened=mysql_num_rows($jobresult1); > $noClosed=mysql_num_rows($jobresult2); > $getlargest = strcmp($noOpened, $noClosed); > > switch ($getlargest) { > case $getlargest > 0: > $counttickets = $noOpened; > while($sumOpen=mysql_fetch_row($jobresult1)) { > $Open = $sumOpen; > // DEBUG > print $Open[0] . "<br>"; > > } > while($sumClosed=mysql_fetch_row($jobresult2)) { > $Closed = $sumClosed; > // DEBUG > print "c" . $Closed[0] . "<br>"; > > } > > Which produces: > 1 > 2 > 3 > 4 > 5 > c1 > c2 > > So the arrays are correctly set up (I think). Actually, no. It looks to me as if each only contains, at any given time, the most recent value you assigned. (That is, $Open[0] only contains the value "5" at the end of the run, and $Closed[0] only contains the value "2".) That, in fact, explains the results of your array_diff() quite nicely. For what you apparently really mean to do, you'll want to replace $Open = $sumOpen; with something that looks more like $Open[] = $sumOpen; (That'll append the value of $sumOpen to the end of the $Open array, rather than overwriting the entire $Open variable with the value of $sumOpen. Make sense? --- Mark Roedel (roedelm@letu.edu) || "There cannot be a crisis next week. Systems Programmer / WebMaster || My schedule is already full." LeTourneau University || -- Henry Kissinger

« previous php.db (#8144) next »