Search form doesn't work
9 posts by 2 authors in: Forums > CMS Builder
Last Post: September 30, 2020 (RSS)
By CommonSenseDesign - September 30, 2020 - edited: September 30, 2020
I have a search form on my site, which doesn't seem to be picking up some keywords. http://wilmotpost.ca/demo/index.php
Searching for the word "indigenous" doesn't show any results, even though there are clearly at least two articles that contain it. That's just one example, but there are others, too. Any idea what might be causing this, please?
<form action="search.php">
<div class="row no-gutters mt-3">
<div class="col">
<input type="text" name="title_keyword,content_keyword,main_article_keyword,author_keyword" value="">
<input type="submit" name="submit" value="Search">
</div>
</div>
</form>
Search form doesn't work after first search
By Carl - September 30, 2020
Hi,
Do you have any examples of keywords that do work? The keywords I tried didn't show any results. Can you share the search.php file? You should use a single word without any commas in your input name and you can use the value from that variable to query the database for any item in your database you wish to query.
PHP Programmer
interactivetools.com
Search form doesn't work after first search
Hi, Carl.
For some reason, it seems to pick up my last name, as I wrote some of the articles, but it doesn't catch anything else!
I've attached the search results page.
Search form doesn't work after first search
By Carl - September 30, 2020 - edited: September 30, 2020
Disclaimer: I haven't tested this yet.
<form action="search.php" method="post">
<div class="row no-gutters mt-3">
<div class="col">
<input type="text" name="query">
<input type="submit" name="submit" value="Search">
</div>
</div>
</form>
After that, on search.php I would change this:
// load records from 'homepage_insets'
list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
'tableName' => 'homepage_insets',
'perPage' => '10',
'loadUploads' => true,
'allowSearch' => true,
));
to something similar:
$query = @$_REQUEST['query']; // this will hold the keyword
// load records from 'homepage_insets'
list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
'tableName' => 'homepage_insets',
'perPage' => '10',
'loadUploads' => true,
'allowSearch' => true,
'where' => " title_keyword LIKE '%".mysql_escape($query)."%' ",
));
Let me know if that works.
PHP Programmer
interactivetools.com
Search form doesn't work after first search
Would this only search one field? i.e. the title field, which contains the headline? I'd like it to search author, content, main_article as well as title.
Search form doesn't work after first search
By Carl - September 30, 2020
Yes, it would search only one field. If you know the names of the other fields, you can do something like
$query = @$_REQUEST['query']; // this will hold the keyword
// load records from 'homepage_insets'
list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
'tableName' => 'homepage_insets',
'perPage' => '10',
'loadUploads' => true,
'allowSearch' => true,
'where' => " title_keyword LIKE '%".mysql_escape($query)."%' OR content_keyword LIKE '%".mysql_escape($query)."%' ",
));
and you can add all the fields you want to search using that format.
PHP Programmer
interactivetools.com
Search form doesn't work after first search
I'm afraid not; I'm getting this error message when I run a search:
MySQL Error: Unknown column 'title_keyword' in 'where clause'
Search form doesn't work after first search
By Carl - September 30, 2020
Try this
$query = @$_REQUEST['query']; // this will hold the keyword
// load records from 'homepage_insets'
list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
'tableName' => 'homepage_insets',
'perPage' => '10',
'loadUploads' => true,
'allowSearch' => true,
'where' => " title LIKE '%".mysql_escape($query)."%' OR content LIKE '%".mysql_escape($query)."%' ",
));
PHP Programmer
interactivetools.com
Search form doesn't work after first search
Perfect! Thank you so much.