Mailing List Archive



Back to the month index Back to the list index

Fernando Maior (fmaior@upol.com.br)
Wed, 21 Apr 1999 19:56:36 -0300


Message-ID: <371E57A4.72149BF@upol.com.br>
Date: Wed, 21 Apr 1999 19:56:36 -0300
From: Fernando Maior <fmaior@upol.com.br>
Subject: Re: How to compare two record sets using Lite?

Hi Wilson, Hi List,

Try msqlDataSeek to rewind the result array.

Do this:

$row1 = msqlFetchRow($res1);
while (#$row1 > 0) {
    msqlDataSeek($res2,0);
    $row2 = msqlFetchRow($res2);
    while (#$row2 > 0) {
        /* proceed... */

        /* get next row... */
        $row2 = msqlFetchRow($res2);
    }
    $row1 = msqlFetchRow($res1);
}

I did not try this feature by myself, yet, but it is on the manual. You
can read:

"msqlDataSeek() allows you to move the data pointer within the result
table. Specifying a location of 0 will rewind the result. The next call
to msqlFetchRow() will return the first row of the result table again."

Hope this can do what you need.

Bye,
Fernando Maior

wilson li wrote:

> Hi All,
> I want to compare two record sets resulted from two
> queries using Lite code similar to the following:
> while ( #$row1 > 0 ) {
> while (#$row2 > 0 ) {
> if ($row1[1] == $row2[1] ){
> /* do something */
> }
> $row2 = msqlFetchRow ($res2);
> }
> $row1 = msqlFetchRow ($res1);
> }
> The problem is that, after looping through $res2 once,
> there seems no way to set the pointer in $res2 back to
> the first record again. So the second while loop can
> only run once and I can't use the above code to
> compare each record in $rec1 with each record in
> $rec2.
> I understand that I can extract all the records in
> $rec2 into an array and then do the comparison. But
> before doing that, I want to make sure that there is
> no better methods for handling this problem.
> Any help will be highly appreciated!
> Wilson
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com