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!

Need to make a search a little more complex..can you help?

Status
Not open for further replies.

pjwraith

Technical User
May 17, 2002
12
GB
I have put the search code below that I am using, it currently searches for the beginning of a postcode in a mysql field.

Code:
$sql = "select * from aromaol where town = '".$_POST['seek']."' or postcode = '". $_POST['seek'] ."'"; 
$result = mysql_query($sql,$conn)or die (mysql_error());  


if (mysql_num_rows($result)==0){
echo "No Match Found";
}else{
while ($row = mysql_fetch_assoc($result)){
 echo &quot;Name: &quot; .$row['forename'].&quot; &quot;.$row[&quot;surname&quot;].&quot;<br>&quot;;
 echo &quot;&quot;.$row[&quot;town&quot;].&quot;<br>&quot;; 
 echo &quot;Tel No: &quot;.$row['telno'].&quot;&quot;; 
 echo &quot;  Mobile No: &quot;.$row[&quot;mobno&quot;].&quot;<br>&quot;;
 echo &quot;Link:  <a href=\&quot;[URL unfurl="true"]http://&quot;.$row[/URL]['weblink'].&quot;\&quot;>Visit their webpage</a><br><br>&quot;;


However the data added to the mysql database originated in an access database where the full postcode was shown ie: AA11 1AA. This was manually altered to strip the second part of the postcode off for confidentiality reasons. The Access database has since become very active with a lot of new entries and updates. What I would like to do is import the full postcode in future, means an easy automated process, and modify the search.

The search is allowed to have 4 characters on the input screen as a maximum, what I need to do is 1:add a space on the end of the input postcode 2:search and output only matching results for the input postcode AND space. ie inputting AA1 should not give results of all AA1 AND AA11 entries which a standard search and match would...

Can anyone point me to some code snippets or samples that would help me in this?

All replies welcomed, even if it is only to abuse me! :)
 
$zipcode= $_POST['seek'] . &quot; &quot;;

$sql = &quot;select * from aromaol where town = '&quot;.$_POST['seek'].&quot;' or postcode LIKE '&quot;. $zipcode .&quot;%'&quot;;

something like this perhaps
 
You make it look so simple, I was trying to do it a another way entirely which probably explains why I didnt get there!

Thanks for the help
 
I'm always to lazy to come up with complicated sollutions ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top