SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    0 Post(s)
    0 Thread(s)

    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!

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Atlanta, GA, USA
    71 Post(s)
    0 Thread(s)
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts