Getting the ID from a MySql table?

Discussion in 'PHP' started by misterdh, Aug 2, 2010.

  1. #1
    Hi

    $eid2 = mysql_query("SELECT id FROM engines WHERE keyword = '%$tricker_engine%' LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_assoc($eid2);
    $eid = $row['id'];
    PHP:
    I want $eid to be the ID of the row where keyword = '%$tricker_engine%'.

    What is wrong with my code above?
     
    misterdh, Aug 2, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    mysql_fetch_array() I think ?

    
    $eid2 = mysql_query("SELECT id FROM engines WHERE keyword = '%$tricker_engine%' LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_array($eid2);
    $eid = $row['id'];
    
    PHP:
     
    MyVodaFone, Aug 2, 2010 IP
  3. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Use

    $row = mysql_fetch_array($eid2);

    instead of

    $row = mysql_fetch_assoc($eid2);
     
    KingCobra, Aug 2, 2010 IP
  4. po_taka

    po_taka Peon

    Messages:
    14
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $eid2 = mysql_query("SELECT id FROM engines WHERE keyword LIKE ('%".$tricker_engine."%') LIMIT 1") or die(mysql_error());
     
    po_taka, Aug 2, 2010 IP
  5. misterdh

    misterdh Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Fixed it with $row = mysql_fetch_array($eid2);

    Thanks alot guys :)
     
    misterdh, Aug 2, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Depending on the scenario you could also use mysql_insert_id()
     
    danx10, Aug 3, 2010 IP