elis Posted October 31, 2007 Share Posted October 31, 2007 I'm not even sure if this is achievable but I'll try to explain what I want done: In the below code snippet: else { $send = "INSERT INTO advt_apps (appid,name,website,pay_email,pay_emailconf,email,emailconf,banner_image,text_link,comments,ad_length,ad_type,ad_total) VALUES ('','$name','$website','$pay_email','$pay_emailconf','$email','$emailconf','$banner_image','$text_link','$comments','$ad_length ','$ad_type','$ad_total') AND SE"; $sent = mysql_query($send) or die("Query setup failed".mysql_error()); $appc="SELECT * FROM advt_settings WHERE id = 1"; $go=mysql_query($appc); $res=mysql_fetch_array($go); if($ad_type=="text ad") $ad_amount=$res[price_text]; elseif($ad_type=="small banner") $ad_amount=$res[price_banner_small]; elseif($ad_type=="large banner") $ad_amount=$res[price_banner_large]; elseif($ad_type=="inquire") $ad_amount="0"; if($ad_length=="one month") $ad_time=1; elseif($ad_length=="three months") $ad_time=3; elseif($ad_length=="six months") $ad_time=6; elseif($ad_length=="one year") $ad_time="12"; elseif($ad_length=="custom length") $ad_time="0"; $ad_total=$ad_amount * $ad_time; I'm trying to insert the last line of the code "$ad_total" into the MYSQL table. However, if I rearrange the coding so that the below snippet is before the insert query, the "$ad_total" field is not read nor calculated (it's supposed to be two other numerical fields multiplied each other to receive the latter) if($ad_type=="text ad") $ad_amount=$res[price_text]; elseif($ad_type=="small banner") $ad_amount=$res[price_banner_small]; elseif($ad_type=="large banner") $ad_amount=$res[price_banner_large]; elseif($ad_type=="inquire") $ad_amount="0"; if($ad_length=="one month") $ad_time=1; elseif($ad_length=="three months") $ad_time=3; elseif($ad_length=="six months") $ad_time=6; elseif($ad_length=="one year") $ad_time="12"; elseif($ad_length=="custom length") $ad_time="0"; $ad_total=$ad_amount * $ad_time; I'm thinking that if I could select the auto_increment id, which in this case is "appid" as the tables are being inserted, then I could immediately update those tables,based on the "appid", to add the $ad_total field after the insert. I hope my ramblings made sense, I'm not the best at explaining things. To sum everything up, I'm trying to get the $ad_total field added to the MYSQL table, but because of their positioning within the code, it's not being read - if I change the posistion then the leading "else" statement is thrown off. Link to comment https://forums.phpfreaks.com/topic/75569-solved-combined-insertselect-query/ Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 Do a UPDATE after the INSERT? Link to comment https://forums.phpfreaks.com/topic/75569-solved-combined-insertselect-query/#findComment-382327 Share on other sites More sharing options...
elis Posted October 31, 2007 Author Share Posted October 31, 2007 I've tried that but in order to do that I'd prefer the WHERE clause to be based on the auto_increment id, which for someone reason I'm having trouble grabbing. If I use another WHERE element, then I run the risk of updating multiple tables, if for some reason somebody decides to submit the form more than one time with the exact same information. Link to comment https://forums.phpfreaks.com/topic/75569-solved-combined-insertselect-query/#findComment-382330 Share on other sites More sharing options...
elis Posted November 1, 2007 Author Share Posted November 1, 2007 Does anyone have any suggestions, please? Link to comment https://forums.phpfreaks.com/topic/75569-solved-combined-insertselect-query/#findComment-382744 Share on other sites More sharing options...
elis Posted November 1, 2007 Author Share Posted November 1, 2007 I figured it out, it was a matter of correctly rearranging the positioning of the coding like, I originally thought. Some tweaking and head-banging on my keyboard straightened it. Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/75569-solved-combined-insertselect-query/#findComment-382784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.