Jump to content

[SOLVED] Combined Insert/Select Query?


elis

Recommended Posts

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
Share on other sites

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