Getting the ID from a MySql table?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Getting the ID from a MySql table?

Post 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?
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: Getting the ID from a MySql table?

Post 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());
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: Getting the ID from a MySql table?

Post by dominod »

Fixed it with $row = mysql_fetch_array($eid2);

Thanks alot :)
Post Reply