Is there an easier way to do this? (query)

Discussion in 'PHP' started by x0x, Jan 24, 2010.

  1. #1
    // insert the stuff
    $DB->query("INSERT INTO $t[fam] (name,city) VALUES ('$fam_name','$newcity')", __FILE__, __LINE__);
    
    // is there another way to obtain the ID of the freshly inserted info without pulling it again? 
    $famid = $DB->fetch("SELECT id FROM $t[fam] WHERE name='$fam_name'", __FILE__, __LINE__);
    
    // table that is connected to the fam table (id - fam)
    $DB->query("UPDATE $t[mob] SET fam='$famid[id]', famrank='1' WHERE id='$id'", __FILE__, __LINE__);
    PHP:

    Just something that got me wondering.
     
    x0x, Jan 24, 2010 IP
  2. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what templete engine you are use?
    and this is the simplest way
    you cant merge select + update+insert
    i think
     
    astkboy2008, Jan 24, 2010 IP
  3. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #3
    shallowink, Jan 24, 2010 IP
  4. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4

    None. Yeah, I know that they can be merged but I'm not interested in super hardcore queries. Way over my head.



    Brilliant! I knew there had to be something :D
     
    x0x, Jan 24, 2010 IP