Jump to content

Getting the ID from a MySql table?


dominod

Recommended Posts

If you are expecting exactly one result, such as you would be when selecting a primary key or unique index field, don't use a WHERE . . . LIKE query. By doing so, and combining it with a LIMIT 1, there's a good chance you can end up with the wrong record. You should also make sure you returned exactly one record with the query.

$eid2 = "SELECT id FROM engines WHERE keyword = '$tricker_engine' LIMIT 1";
$result = mysql_query($eid2) or die(mysql_error());
if(mysql_num_rows($result) == 1) {
     $row = mysql_fetch_array($result):
     $eid = $row['id'];
} else {
     //If query returns other than exactly one record, results are either not present, or are ambiguous
}

Archived

This topic is now archived and is closed to further replies.

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