Re: Run db query with db query?

From: Date: Tue, 04 Mar 2003 03:45:33 +0000
Subject: Re: Run db query with db query?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-138002@lists.php.net to get a copy of this message
Exactly. I'm using $result for both queries. That's how I discovered the problem: the inner query is over-writing the outer query $result set. Unfortunately my existing db_connect function does not account for multiple queries. I just pass the query as a param -- db_connect($sql). $result is returned for each query, but this only works with single queries; not nested queries. In any case, it doesn't seem terribly efficient to run a query within a query, since the inner query only needs to be run once at the top of the page. Problem now is: How to populate the write_select_options($tables,$form_fields,$where_clause) function; when it returns no variable -- it just echoes out the option values. Looks like I need to modify the function to return a var rather than echoing some output. Most likely just talking to the empty universe at this point ;--) Cheers to all php junkies....... --Noah "Monty" <monty3@hotmail.com> wrote in message news:BA89456E.18C86%monty3@hotmail.com... > What is the code for the inner query? Hard to advise you based on the small > bit of code you posted. > > Are you using the same $result var for both queries? If so, that's why. Just > run two separate queries stored in to different result vars. I do this all > the time with no problems. > > > > From: noah@newminddesign.com (Cf High) > > Newsgroups: php.general > > Date: Mon, 3 Mar 2003 16:45:52 -0800 > > To: php-general@lists.php.net > > Subject: Run db query with db query? > > > > Hey all. > > > > Got a problem here: > > > > 1) I have a page that queries our db for info > > > > 2) Based on the # of rows returned I loop through to create a set of > > formfields for each customer > > > > 3) Within this loop I run another query to retrieve option elements for > > a particular category > > > > The problem is that the inner query is overwriting the result resource for > > the outer query. So: > > > > while ($q = mysql_fetch_row($result)) { > > > > build form tables for each client and run inner query > > > > html stuff > > > > /* Calls db query to populate particular option category */ > > write_select_options($tables,$form_fields,$where_clause); > > > > } > > > > What's the conventional method for running queries within queries? > > > > Any leads most appreciated, > > > > --Noah > > > > -- > > > > > > >

« previous php.general (#138002) next »