SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    0 Post(s)
    0 Thread(s)

    Syntax assistance please.

    Hopefully a nice easy one (well not so easy for me!)

    HTML Code:
    	$sql = 'Insert into property set house_name="' .$house_name_text. '" , 
    	house_number="' .$house_number_text. '" , 
    	addline1="' .$addline1_text. '",
    	addline2="' .$addline2_text. '",
    	town = "' .$town_text. '",
    	county = "' .$county_text. '",
    	postcode = "' .$postcode_text. '",
    	job_status = "' .$job_status. '",
    	contact = "' .$contact_text. '",
    	access = "' .$access_text. '",
    	msg = "' .$msg_text. '",
    	date_job_rec = "' .$date_job_rec. '", 
    	client = "'.$client.'", 
    	fee = client.fee ';
    As you can see it is an INSERT command query. The problem part i have is the very last element. I want this last field 'fee' to be given the value of the field 'fee' held in a different table 'client'.

    (I dont want to join the value as if the client fee should change in future i do not want the historic instructions altered to represent the new fee)

    fee is INT in both cases.

    I know this is a simple one, but we all have to start somewhere

    Many thanks in advance


  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    161 Post(s)
    4 Thread(s)
    Instead of INSERT... SET... use the INSERT ... SELECT... construction:
    $sql = "
      INSERT INTO property 
        , '$house_number_text', 
        , ....
        , '$client'
        , client.fee
      FROM client
      WHERE add the conditions to get the right fee value from the client table
    Make sure you get only one fee value from the client table, because a row will be inserted for each fee value returned.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts