Page 1 of 1

Getting the ID from a MySql table?

Posted: Mon Aug 02, 2010 7:20 am
by dominod
Hi

Code: Select all

$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'];
I want $eid to be the ID of the row where keyword = '%$tricker_engine%'.

What is wrong with my code above?

Re: Getting the ID from a MySql table?

Posted: Mon Aug 02, 2010 8:26 am
by internet-solution
If you are using wild card characters (%) then you will have to use LIKE operator

Code: Select all

$eid2 = mysql_query("SELECT id FROM engines WHERE keyword LIKE '%$tricker_engine%' LIMIT 1") or die(mysql_error());

Re: Getting the ID from a MySql table?

Posted: Mon Aug 02, 2010 10:41 am
by dominod
Fixed it with $row = mysql_fetch_array($eid2);

Thanks alot :)