Jump to content

search


jeff5656

Recommended Posts

Here's how a user can search for something in ONE field (mrn).  How do write it so the record is retrieved if the search term occurs in ANY field in the record? So if "jeff" occurs anywhere, pull that record.

 

$query = "SELECT * ".
	"FROM icu WHERE mrn = '" . $_POST['mrn'] . "' ".
	"ORDER BY rcf_date2 ";
$results = mysql_query ($query) or die (mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/145949-search/
Share on other sites

The most straightforward way is to simply check each field explicitly:

 

$query = "SELECT * FROM icu ".

      "WHERE mrn = '" . $_POST['mrn'] . "' ".

      "OR field2 = '" . $_POST['mrn'] . "' ".

      "OR field3 = '" . $_POST['mrn'] . "' ".

...

      "ORDER BY rcf_date2 ";

 

Also, you may want to use "LIKE" to get partial matches, like so:

 

$query = "SELECT * FROM icu ".

      "WHERE mrn LIKE '%" . $_POST['mrn'] . "%' ".

      "OR field2 LIKE '%" . $_POST['mrn'] . "%' ".

      "OR field3 LIKE '%" . $_POST['mrn'] . "%' ".

...

      "ORDER BY rcf_date2 ";

 

... to match field data such as "Jeff5656" with search term "jeff".

Link to comment
https://forums.phpfreaks.com/topic/145949-search/#findComment-766240
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.