ivalea Posted October 13, 2006 Share Posted October 13, 2006 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:[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', '', '', '', '', ''");}else{echo 'something here';}[/code]Desperately need help with this - project is due today and this is the last piece that I need to lauch! Thanks! :) Link to comment https://forums.phpfreaks.com/topic/23910-insert-statement-based-off-of-select-statement-results/ Share on other sites More sharing options...
fenway Posted October 14, 2006 Share Posted October 14, 2006 I'm not sure I understand what the problem is... though why not do this with an INSERT INTO... SELECT WHERE? Link to comment https://forums.phpfreaks.com/topic/23910-insert-statement-based-off-of-select-statement-results/#findComment-108831 Share on other sites More sharing options...
ivalea Posted October 14, 2006 Author Share Posted October 14, 2006 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! :) Link to comment https://forums.phpfreaks.com/topic/23910-insert-statement-based-off-of-select-statement-results/#findComment-108861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.