Using LIKE error (Not a select statement issue)
Posted: Fri Sep 30, 2005 3:39 pm
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.....
Thanks in advance for the help
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> </td>";
echo "<td align='center'> </td>";
echo "<td>";
if ($row{'customers_company'} == ("%Mary%")){
echo "Mary Kay";
}else
{
echo $row{'customers_company'} . "</td>";
}
echo "<td align='center'> </td>";
echo "<td align='center'> </td>";
echo "</tr>";
}
mysql_close($dbh);