Jump to content


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


insert statement based off of select statement results??

Recommended Posts

Hi, I'm trying to grab the results of a select statement and only if the result is equal to a certain string use an insert to add to a different table.  I looks like my select is okay - but now I'm wondering how I can run the insert... here is my code:
$a = mysql_query("select * from orders_products as op, customers as c where op.orders_id = '000099' and op.products_id = '29' and c.customers_id = '14'");
while($row = mysql_fetch_assoc($a)){
$id = $row['products_model'];
$email = $row['customers_email_address'];
$custid = $row['customers_id'];
if ($id == 'CBT-0100'){
echo 'Now run the insert query using $email, $custid, and $id';
$z = mysql_query("insert into students (students_id, customers_id, students_pmodel, students_email, students_mod1, students_mod2, students_mod3, students_manual, students_cert) values ('', '$custid', '$id', '$email', '', '', '', '', ''");
echo 'something here';

Desperately need help with this - project is due today and this is the last piece that I need to lauch!  Thanks! :)

Share this post

Link to post
Share on other sites
I'm not sure I understand what the problem is... though why not do this with an INSERT INTO... SELECT WHERE?

Share this post

Link to post
Share on other sites
Not sure - just that I need the "if" in there to make sure that the order contains that specific product model.

So, I first need to pull the order information and then select the model number purchased.  Only if the model number purchased is equal to a specific string, then insert into the students table. 

I'll look into doing an INSERT INTO .... SELECT though - thanks! :)

Share this post

Link to post
Share on other sites


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.