Jump to content

Search a database?


Hangwire

Recommended Posts

Hello all. First of all, if this isn't the right place for this topic, please excuse me and may the moderators/admins move it where it should belong. :)

 

Second, I'm trying to make a mysql search - Everything works, but if say, a user searches for 34 it displays all numbers that have the number 34 in them.

 

I want the results to be exact - if a user searches for 34, to display only 34, not 334, 5034 or 3401 (like it happens now).

 

Here's the code:

 

<?php
mysql_connect ("**************", "*******","*****")  or die (mysql_error());
mysql_select_db ("********");

$term = $_POST['term'];

$sql = mysql_query("select * FROM countries WHERE cocode LIKE '%$term%'");

while ($row = mysql_fetch_array($sql)){
    echo '<br/> Code: '.$row['cocode'];
    echo '<br/> Country: '.$row['coname'];
    echo '<br/><br/>';
    }

?>

 

If you have any questions, you're welcome to ask them in the thread. 

 

Thank you in advance :)  ::)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.