Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.