thefortrees Posted June 18, 2007 Share Posted June 18, 2007 Hi all - I am trying to figure out if there is anyway to combine the 2 queries in my code. In the second query, I want to insert the businesses_id I retrieve from the first query into the table. Is there any way to select businesses_id and insert it with a text field in the form in one query? Thanks! My two tables are as follows: businesses ---------- Fields: businesses_id lob (type of business) ---------- questions --------- questions_id businesses_businesses_id (obviously, businesses_id from business table) question (text) //Add a question - get businesses_id from businesses where posted lob = lob in businesses table. Then add //businesses_id and question to questions. $query = "SELECT businesses_id FROM businesses WHERE lob = '$_REQUEST['lob']"; $result = mysql_query($query); $row = mysql_fetch_array($result); $businessid = $row[0]; $question = $_REQUEST['question']; $query = "INSERT INTO questions (businesses_businesses_id, question) VALUES ('$businessid', '$question')"; Quote Link to comment https://forums.phpfreaks.com/topic/56116-combining-queries/ Share on other sites More sharing options...
cooldude832 Posted June 18, 2007 Share Posted June 18, 2007 are you looking for an optimization here or what? because i don't see a need to make it into a single query Quote Link to comment https://forums.phpfreaks.com/topic/56116-combining-queries/#findComment-277190 Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 combining query is possible but why ?? it will only makes your query more complicated and the one the have their is fine query first to get the id and insert the data that has been retrieve. forms??? is this what you mean <input type="text" name = "ASTIG" value="<?=your desired value here?>"> hope that helps bro!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/56116-combining-queries/#findComment-277206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.