Re: nesting mySQL queries/while statements

From: Date: Tue, 09 Jan 2001 00:31:38 +0000
Subject: Re: nesting mySQL queries/while statements
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33360@lists.php.net to get a copy of this message
on 1/5/01 9:05 PM, Maurice Rickard at maurice@mauricerickard.com wrote: > Hello, > > I may not be explaining what I'm trying to do correctly; I'm coming > from an extensive WebCatalog background, which uses a rather > different vocabulary. > > I'm working on a test site to train myself in PHP/mySQL. I have a > lot of sample data, organized into categories ("flavors"). While > each table row is unique, there are instances where data is > duplicated. Here's an example: > > [...] I don't have much MySQL experience, but probably your problem is you're trying to do another query while your result set is open in the first query. To do it the way you're doing it, you'll probably need a second connection to the database. The outer query uses one connection and the inner query uses the second. But it would probably be better to just do the query in your first example, grabbing all the rows. Then, in your loop to process the results, just keep track of the last "lastname" you've seen. If the current last name is different, it's a new last name, so start a new section and output that last name, then carry on with the results. This way you do only one connection and query. As long as you sort by last name it will work properly. Does that make sense? Hope that helps, Geoff

« previous php.general (#33360) next »