PDA

View Full Version : php IF ELSE statement



evandaeman
29 Jan 2007, 11:36 AM
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???

Alan
04 Feb 2007, 12:07 PM
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.



<?php
$url_length = strlen($url);

if($url == substr($source,0,($url_length-1)))
{
echo $fname;
}
?>

That should work for what your trying to do.