Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: multiple open handles to mysql? (loops: fetches within fetches) Date: Fri, 12 Dec 2014 07:51:58 +0100 Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Er2v47ViuvOtgoBa+hR0wA260I1jEjNViIUBiPni1xIpagmx2I Cancel-Lock: sha1:guAWW5TdSbEUcSf5ZqhbpVOPduA= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: Xref: csiph.com comp.lang.php:14702 On 12/12/14 04:45, Jerry Stuckle wrote: > On 12/11/2014 12:25 AM, oldyork90@yahoo.com wrote: >> >> $sth01 blah blah ... bind vars >> $sth02 (same) >> >> while ($seth01->fetch()) >> while ($seth02->fetch()) >> >> I'm having difficulty building this with mysql 5.5 and php(mysqli). >> In an other language/database I can have >> open and nested active fetches as above. >> >> If this is not possible then how is it done? Do you buffer the whole result, close, and reuse the handle? >> >> Thanks - rookie >> > > The real question here is - why do you think you need to do this? And > your logic is flawed. > > Even if you did get two different result sets, the first time through > the loop $seth02 will be emptied and all future requests will return > false. The same thing will occur in any language (and any database). > > I think a better solution would be to create the appropriate SQL to > return the results you want in one request. > Just looking at the OP, I would guess the needed change to the query would be a JOIN and ORDER BY, as I would guess on that the first query fetches data from a group table and the second fetches those items which belongs to the group table. Maybe better option for the OP to ask question about the query itself at comp.databases.mysql -- //Aho