Page 1 of 1

Using LIKE error (Not a select statement issue)

Posted: Fri Sep 30, 2005 3:39 pm
by phoenixx
I'm using a looped statement after a mysql select and need the output to alter according to the table data.

If the value of a row is LIKE abc but the actual value is abcde, then I want it to input a static response.

Reality: We have thousands of customers, and not all of them enter their company name the same.... for instance someone that works for Mary Kay may put 'marykay' or 'Mry Kay' or, etc..... I want it to search for any instance of "mary" and output "Mary Kay"

Here's a sample of what I've got that isn't working.....

Code: Select all

$dbh = mysql_connect($hostname, $username, $password) 
	or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db("swjsne83_tester",$dbh) 
	or die("Could not select first_test");
$result = mysql_query("SELECT * FROM orders GROUP BY customers_company");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td align='center'>&nbsp;</td>";
echo "<td>";
	if ($row{'customers_company'} == ("%Mary%")){
		echo "Mary Kay";
	}else 
	{
echo $row{'customers_company'} . "</td>";
}
echo "<td align='center'>&nbsp;</td>";
echo "<td align='center'>&nbsp;</td>";
echo "</tr>";
}
mysql_close($dbh);
Thanks in advance for the help

Posted: Sat Oct 01, 2005 12:35 am
by ruchit
if i've understood your problem correctly, you can use

Code: Select all

if(preg_match("/Mary/", $row{'customers_company'}){ //You can use regex expressions for other combinations
      echo "Mary Kay";
   }
else   { 
}

Posted: Sat Oct 01, 2005 12:22 pm
by phoenixx
Worked Great!!!

Many Thanx!