MySQL Forums
Forum List  »  Newbie

Querying Database Using LIKE function PHP4
Posted by: Paul Taylor
Date: March 25, 2005 02:07PM

Hi I have recently started to learn PHP & MySQL, I am however completely stuck. I have a search facility form where the user can select a category and enter a keyword. This will bring up results but only if you enter the exact word.
I understand that there is a LIKE function, I have tried to place this in my code but nothing works.
Can anyone please help - It would be greatly appreciated, my current code is below, Cheers Paul

<?php
switch($select)

{
case Name : $QuerySelect = "SELECT*FROM bars WHERE(bars.name = '$search')"; break;

case Address : $QuerySelect = "SELECT*FROM bars WHERE(bars.address = '$search')"; break;

case Telephone : $QuerySelect = "SELECT*FROM bars WHERE(bars.tele = '$search')"; break;

case Email : $QuerySelect = "SELECT*FROM bars WHERE(bars.email = '$search')"; break;

case Comments : $QuerySelect = "SELECT*FROM bars WHERE(bars.comments = '$search')"; break;

}

switch($selectall)
{
case ALL : $QuerySelect = "SELECT*FROM bars WHERE 1"; break;
}

$result = mysql_query($QuerySelect);
//----------------------------------- SEARCH THE ROWS IN THE bars TABLE -----------------------------------------------

$numrows = mysql_numrows($result);
if($numrows != 0)
{
while($row = @mysql_fetch_array($result))
{
//----------------------------display results--------------------


echo "<tr>
<td height=\"10\">

<table width=\"600\" height=\"130\" border=\"0\" cellpadding=\"0\" cellspacing=\"5\" class=\"h3\">
<tr>
<td width=\"600\" align=\"left\" valign=\"top\"><table width=\"590\" height=\"116\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"h3\">
<tr class=\"h3withborder\">
<td width=\"155\" align=\"left\" valign=\"top\" background=\"images/noimageavailable.jpg\" class=\"h3withborder\"><img src=\"images/". $row["imageone"]. ".jpg\"</td>
<td width=\"280\" align=\"center\" valign=\"top\" bgcolor=\"#FFFFFF\"><table width=\"280\" height=\"130\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\" class=\"h3withborder\">
<tr align=\"right\" valign=\"top\" class=\"h3withborder\">
<td width=\"176\" height=\"20\" align=\"left\" valign=\"middle\">". $row["name"]. "</td>
<td width=\"100\" height=\"20\"><div align=\"right\">
<table width=\"100\" height=\"20\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td align=\"right\" valign=\"middle\">". $row["tele"]. "</td>
</tr>
</table>
</div></td>
</tr>
<tr align=\"left\" valign=\"top\" class=\"h3withborder\">
<td height=\"40\" colspan=\"2\">". $row["address"]. "</td>
</tr>
<tr align=\"left\" valign=\"top\" class=\"h3withborder\">
<td height=\"20\" colspan=\"2\">". $row["email"]. "</td>
</tr>
<tr align=\"left\" valign=\"top\" class=\"h3withborder\">
<td height=\"40\" colspan=\"2\">". $row["comments"]. "</td>
</tr>
</table></td>
<td width=\"155\" align=\"right\" valign=\"top\" background=\"images/noimageavailable.jpg\" class=\"h3withborder\"><img src=\"images/". $row["imagetwo"]. ".jpg\"</td>
</tr>
</table></td>
</tr>
</table>

</td>
</tr>";


}
}
else
{
echo "Can't find a record for $search in the $select field";
}
?>

Options: ReplyQuote


Subject
Written By
Posted
Querying Database Using LIKE function PHP4
March 25, 2005 02:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.