Results 1 to 2 of 2

Thread: php IF ELSE statement

  1. #1
    Join Date
    May 2004
    Posts
    75

    php IF ELSE statement

    hi... i have a couple of tables in my database...

    i have database called leads with these fields

    id
    fname
    lname
    source

    data example:
    1, evan, lastname, http://www.google.com/search?blabla
    1, evan, lastname, http://www.yahoo.com/search?damn
    1, evan, lastname, http://www.msn.com/search?ding
    1, evan, lastname, http://www.google.com/search?blueblue



    i have a 2nd table called URL with these fields
    id
    url

    data:
    1, http://www.google.com
    2, http://www.msn.com


    now... i want to tell my php script...

    if ($source LIKE %$url%) {
    echo $fname;
    }


    i notice that i can't use LIKE statement when i use "if/else"

    what do you think would be best way to match the data?

    i know i can do a query in mySQL using LIKE statement...

    but are there similar operators for IF/ELSE???

  2. #2
    Join Date
    Feb 2007
    Location
    Ireland
    Posts
    1,007
    Assuming you don't want to enter a query, you could do it this way:

    I'm going to assume that you have extracted all the variables from the database already.

    Code:
    <?php
    $url_length = strlen($url);
    
    if($url == substr($source,0,($url_length-1)))
    {
       echo $fname;
    }
    ?>
    That should work for what your trying to do.

Posting Permissions

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