Quick search for variables

Right, I have a table with two fields. One of these is $event_ID, the other is $object_ID. In php, I am running a while loop for all my $event_ID’s taking data from another table. Now, in that while loop all I want to do is search through the table I just mentioned and find any matching $event_ID’s. If the $object_ID = 7 I simply then want to echo a little bit of data.

What’s the best way of doing this? I was thinking that I should create an SQL query, i.e. "SELECT event_ID, object_ID FROM event_object_table WHERE event_ID = ‘$event_ID’, and then running another WHILE loop with an IF clause saying something like:

IF ($object_ID = 7) {echo "true";}

Is this the best way to do this? Or is there a more efficient way? That’s really what I’m after!

More efficient: WHERE event_id = ‘$event_ID’ AND object_ID = 7

That way you only retrieve the rows you’re actually interested in.

Note: You only need ‘’ around a variable like that if the field type is a non-numeric type (VARCHAR, TEXT, DATETIME, etc). If it’s numeric (INT, FLOAT, etc) you just put the variable/value.