Using LIKE error (Not a select statement issue)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phoenixx
Forum Newbie
Posts: 2
Joined: Fri Sep 30, 2005 3:33 pm

Using LIKE error (Not a select statement issue)

Post 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
ruchit
Forum Commoner
Posts: 53
Joined: Mon Sep 26, 2005 6:03 am

Post 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   { 
}
phoenixx
Forum Newbie
Posts: 2
Joined: Fri Sep 30, 2005 3:33 pm

Post by phoenixx »

Worked Great!!!

Many Thanx!
Post Reply