Wanda Marston
asked on
How do I add a search function to my website?
How do I add a search function to my website?
There are a number of ways. But you need to specify what you want the viewers to search for and what you want them to find.
What about using : https://lucene.apache.org/solr/features.html
ASKER
My viewers are all members of a website who can post messages for all other members to view. SO I would like them to be able to search through ALL of the messages in the database to find anything that might match up with what they might be looking for such as ALL message from a certain City or a company date or maybe a date range.
ASKER
leakim971 - I will check out your suggesion. Thanks.
Of if you're running a CMS, likely there are many search plugins to choose from.
Suggestion: Post your URL, for additional/specific comments for your site type.
Suggestion: Post your URL, for additional/specific comments for your site type.
ASKER
Hi,
You will need to create a form and get the data from DB based on the form value.
I would use AJAX to post to PHP then create a MySQL query that reflect the posted value.
here some tutorials to help you to start
https://www.webslesson.info/2019/03/php-ajax-live-search-with-multiple-value.html
https://www.qandeelacademy.com/lesson/jquery-advance-tutorial/wCsPAquMNVw
https://learncodeweb.com/php/php-crud-in-bootstrap-4-with-search-functionality/
You can use Datatables with Yadcf filters (you load all data base on a request, the user can filter the result)
I'm using Datatables for all my project this have everything ready to use for your tables
https://datatables.net/
https://yadcf-showcase.appspot.com/
You will need to create a form and get the data from DB based on the form value.
I would use AJAX to post to PHP then create a MySQL query that reflect the posted value.
here some tutorials to help you to start
https://www.webslesson.info/2019/03/php-ajax-live-search-with-multiple-value.html
https://www.qandeelacademy.com/lesson/jquery-advance-tutorial/wCsPAquMNVw
https://learncodeweb.com/php/php-crud-in-bootstrap-4-with-search-functionality/
You can use Datatables with Yadcf filters (you load all data base on a request, the user can filter the result)
I'm using Datatables for all my project this have everything ready to use for your tables
https://datatables.net/
https://yadcf-showcase.appspot.com/
ASKER
The information that my viewers would be searching for at this point is just in ONE database which contains the notices that all the viewers would be posting.
SO they can look for - company name or organization - monetary amount (words or numbers) - currency - timeframe - geographical area - description of the problem.
How hard would it be to switch from one type of search engine to another if the search engine was not performing as expected?
I am using PHP and MSQL.
Thanks
SO they can look for - company name or organization - monetary amount (words or numbers) - currency - timeframe - geographical area - description of the problem.
How hard would it be to switch from one type of search engine to another if the search engine was not performing as expected?
I am using PHP and MSQL.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay I would like to try to write my own. Can I do this with PHP?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay Thanks. I have been attempting to do my own code from scratch and as you say it should be simple. This kind of works but I am not getting any kind of return.
<?php
$output = ' ';
if (isset($_POST['search'])) {
$searchkey = $_POST['search'];
$searchkey = preg_replace ("#[^0-9a-z]#i","" , $searchkey);
$q = mysql_query("SELECT * FROM notices WHERE `organization` LIKE '%$searchq%' OR `location` LIKE '%searchq%'");
$count = mysql_num_rows($q);
}
if ($count == 0) {
$output = 'There was no search results!';
}else{
while ($row = mysql_fectch_array (q)) {
$organization = $row['organization'];
$location = $row['location'];
$output .= '<div> '.$location.' '.$organiztion.' <div>';
}
}
?>
"mysql_query" Warning: This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. What version of PHP are you running?
https://www.php.net/manual/en/function.mysql-query
https://www.php.net/manual/en/function.mysql-query
ASKER
7.1 I pulled bits of code from other pages that I have running.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I entered the following Mysql query this is what I received, which kind of makes sense.
SELECT * FROM notices WHERE `organization` LIKE '%$searchq%' OR `location` LIKE '%searchq%'
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0013 seconds.)
There were no errors in the PHP log.
Thanks,
SELECT * FROM notices WHERE `organization` LIKE '%$searchq%' OR `location` LIKE '%searchq%'
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0013 seconds.)
There were no errors in the PHP log.
Thanks,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lenamtl is right. When you enter it directly you need to use real values because MySQL knows nothing about PHP variables. And in your PHP code, PHP replaces the variables with the values passed to the page before sending it to MySQL.
ASKER
When I entered
SELECT * FROM notices WHERE `organization` LIKE 'men die' OR `location` LIKE 'Tombstone, Wyoming'
I got the same error message
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0014 seconds.)
SELECT * FROM notices WHERE `organization` LIKE 'men die' OR `location` LIKE 'Tombstone, Wyoming'
I got the same error message
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0014 seconds.)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay thanks. I actually thought I had tried that so I don't know what I did BUT when I copied and pasted the above code, MySql returned the whole row of information, which is what I am trying to do.
So my code has to get the information and post it on the page so then the person who did the search can then click on it and communicate with the person who had posted the information.
So my code has to get the information and post it on the page so then the person who did the search can then click on it and communicate with the person who had posted the information.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for replying so quickly. Experts-Exchange is my life saver.