Justtechjobs.com Find a programming school near you






Online Campus Both


php-db | 2001041

Re: [PHP-DB] array_diff usage From: Martin Skjöldebrand (chimbis <email protected>)
Date: 04/02/01

On Monday 02 April 2001 15:41, you wrote:
> > -----Original Message-----
> > From: Martin Skjoldebrand [mailto:chimbis <email protected>]
> > Sent: Saturday, March 31, 2001 10:52 PM
> > To: php-db <email protected>
> > Subject: [PHP-DB] array_diff usage
> >
> >
> > I'm daft. I don't understand the PHP Manual.
> >
> > I have two arrays:
> > Open[0] contains 1 2 3 4 5
> > Closed[0] contains 1 2
> >
> > Now:
> > $test = array_diff($Open, $Closed);
>
> Given the setup you've described, I think you might actually want
>
> $test = array_diff($Open[0], $Closed[0]);

OK, I'll try that.

> > $lines = count($test);
> > print $lines;
> >
> > Gives me: 1
> > I thought it should be 3.
>
> Seems appropriate, given the information you've provided. $Open and
> $Closed each have only one element (0).
>
> > While:
> > for ($counter =0; $counter <= $lines -1; $counter++)
> > {
> > print $test[0];
> > }
> >
> > gives me "5".
>
> 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'm getting them from a database. Two SELECT queries one get the open
tickets, one get the closed ones.

                 $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>";
                                 
                                }

I'm going to manipulate both arrays, so I copy them to "backups"
DEBUG lines produce:
1
2
3
4
5
c1
c2

HTH,

Martin S.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe <email protected>
For additional commands, e-mail: php-db-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>