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
https://forums.phpfreaks.com/topic/255078-search-a-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.