Jump to content

combining queries


thefortrees

Recommended Posts

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')";

Link to comment
https://forums.phpfreaks.com/topic/56116-combining-queries/
Share on other sites

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!!!!! :-[

Link to comment
https://forums.phpfreaks.com/topic/56116-combining-queries/#findComment-277206
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.