Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search for any part of the field?

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194


How can I search for any part of the field?
I used where (name like '$s_name') to search the whole field, i.e. I want to input “jua” in the form to retrieve juan and juana etc…

<?php

//connections goes here

if($submit){
$query=&quot;select name,phone,email from contact where (name like '$s_name')&quot;;
$result=mysql_query($query)or die (&quot;Error in query: $query. &quot; . mysql_error());
$num=mysql_num_rows($result);
}

?>
<html>
<body>
<form method=&quot;post&quot; action=&quot;<?php echo $PHP_SELF ?>&quot;>
<table align=&quot;center&quot;>
<tr>
<td><input type=&quot;text&quot; name=&quot;s_name&quot;></td>
</tr>
<tr>
<td><input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot; search &quot;></td>
</tr>
</table>
</form>

Thanks in advance.
 
The % character matches anything in SQL LIKE searches.
Try using
Code:
 $query=&quot;select name,phone,email from contact where (name like '%$s_name%')&quot;;
instead.
If $s_name contains &quot;jua&quot; (as in your post), this would match what you want and also &quot;1juan&quot; or &quot;7jua&quot;. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top