Single Search box to search all fields

jue_mue

New member
Hi Debbie

Thanks for the clarification.


In terms of my quick search installation there is no term like ' AND present_search_form_field != 0'.... so there's nothing to remove.

Regards

Juergen
 

DebbieS

DaDaBIK Guru
When I looked at your DB yesterday, I used the countries table as suggested. It seemed to pull in all the text, text_area, etc fields - as the SQL is written to do.

What fields appear to be missing? I cannot access your DB any longer, so I cannot look.
 

jue_mue

New member
Hi again

Yes, of course, because all fields are present in the search form.

You still should have access to the db as I did not change your login.

Cheers,

Juergen
 

DebbieS

DaDaBIK Guru
I can login from my home PC (for some reason it did not work from my work PC).

With the login I have, I cannot look to see which fields are missing from the quick search field list.
You're gonna have to provide a list of the fields in the tables that are not showing up in the quick search field list. In my installs where I'm using this, I removed the line I mentioned (so it matches yours) and it searches through all the text, textarea, richeditor fields in the database whether they are in the search form or not.
 

jue_mue

New member
Hi debbie

I removed the field 'Region' from the search form configuration. When using the quick search now, searching for 'Asia' e.g. does not show any results though the quick search seems to include this field into its search... have a look when you find time.

I am off for a week and will look at it when I'll be back.

Cheers again,

Juergen
 

DebbieS

DaDaBIK Guru
Alrighty ... I've found the *possible* solution.
I never noticed this in my installs before because any fields that I've not set to show in the search form, I've not wanted users searching in them anyways. That said, if you want the quick search to include all fields regardless of whether they are included in the search form or not, you will have to try this and see if it works ...

In the quick search form itself, add another hidden form field to the form (bold):
[pre]
<input type="hidden" name="operator" value="or">
<input type="hidden" name="allFieldsQS" value="1">
[/pre]

Then in business_logic.php, look for the function build_where_clause.
In that function you will need to add the check for the hidden field above (bold items):
Look for this line in the build_where_clause function:
[pre]
if ($fields_labels_ar[$i]["present_search_form_field"] == "1"){
[/pre]

And update it with this:
[pre]
if (($fields_labels_ar[$i]["present_search_form_field"] == "1") || (isset($_POST["allFieldsQS"]) && ($_POST["allFieldsQS"] == 1)) {
[/pre]

I think that should do it. Give it a whirl and post back the results.
 

jue_mue

New member
Hi DebbieS

I did exactly what you proposed (double-checked it several times) and replaced the line in business_logic.php (and the form as well). Actually, there are two instances in the business_logic file.

However, I get a blank page now...

Regards

Juergen
 

meanster99

Well-known member
Hi Debbie,

Unfortunately, I got sidetracked from this project for quite sometime so didn't get around to responding to your last post. Sorry. However, Jue_Mue did make me realise what the problem was - it was only searching the fields present in the search form! So having now read your latest post above, I hope to be able to add the fields that were not being searched as searchable fields in my config. Although as it's been a few months since I touched this project, I hope I can find everything OK!!

Thanks again so much for this - just goes to show, even when you think you can't find a solution, given long enough someone else will! Big thanks to all contributors.

Matt
 

DebbieS

DaDaBIK Guru
Juergen ... re blank page ... make sure you have the appropriate number of brackets surrounding your if statements. This is likely the cause of the blank page ... the complete statement is surrounded by brackets and all sub-statement are surrounded by brackets:

if ((part one) || (part two)) {

Double check your brackets and curly braces, etc.

Matt ... glad you found this info useful. As previously stated, I've not added this to my installs as I don't want them to search in fields I've not deemed "searchable".
 

jue_mue

New member
Hi Debbie

I double and triple checked it but everything seems to be alright. This the line a added / changed:

if (($fields_labels_ar[$i]["present_search_form_field"] == "1") || (isset($_POST["allFieldsQS"]) && ($_POST["allFieldsQS"] == 1)) {

I am still getting a blank page...

Juergen
 

DebbieS

DaDaBIK Guru
Because of the smiley in there, I'm not sure it is correct ... is it like this:

[pre]
if (($fields_labels_ar[$i]["present_search_form_field"] == "1") || (isset($_POST["allFieldsQS"]) && ($_POST["allFieldsQS"] == 1))) {
[/pre]

... and as I was removing the smiley, I saw I missed one closing bracket - should be 3 at the end:
one to close ($_POST["allFieldsQS"] == 1)
one to close the (isset ... && ($_POST...))
and one to close the entire if.

Try that and see. It's always the number of brackets that gets me in trouble.
 

jue_mue

New member
Debbie,

I know what you mean... ;-) I think I counted them but did not realized the missing one... Thanks again, the blank page issue has been solved. However, the search function for fields not activated in the config still does not work. :-(

Juergen
 

DebbieS

DaDaBIK Guru
Juergen

Can you turn on display_sql and debug options in config.php so I can have a look at the SQL created from the search?

Thanks!
 

jue_mue

New member
Hi Debbie

Sorry for the late reply... too busy... strangely, I got it working for the database I showed you, no idea how and why.

However, implementing the quick search for fields not included in the the search config for another database (the more important one) does not work yet. I still have to investigate and will keppt you updated.

Regards

Juergen
 

jue_mue

New member
Hi Debbie

Just to let you know: everthng is fine and working now! Thanks a lot for your support and advise - highly appreciated.

Regards

Juergen
 

robidigital

New member
The original code provided here does not work in the latest version of Dadabik. Below is the code I've used which works with the new version and solves a bug in the old search code.

[pre]

<?php
if (($_GET["function"] != "show_search_form")) { //this if statement prevents the Quick Search form to show up on the Advanced Search page
?>

<?php

$sqlcols = "SELECT name_field FROM ".$prefix_internal_table."forms WHERE type_field IN ('text','textarea','rich_editor') AND table_name LIKE '".$table_name."';";

$searchall = execute_db($sqlcols, $conn);

// as long as column names are found meeting criteria above, construct form fields
while ($searchfield = fetch_row_db($searchall)){

// This line not required -- used to get list of column names into array that can be printed to screen to verify columns it has found
$allfields .= $searchfield[0].' ';

// sets the search select type to 'contains' for each column included in search request
$allseltypes .= '<input name="'.$searchfield[0].$select_type_select_suffix.'" type="hidden" value="contains">';

// creates a hidden form field for each column included in search request
$fieldterm .= '<input name="'.$searchfield[0].'" type="hidden" value="">';

// writes onSubmit values to form open tag to set the value for each hidden field defined above
$submitline .= 'document.searchall.'.$searchfield[0].'.value = document.searchall.allterm.value;';

} // end while column names are found

// uncomment to display database table columns found which will be included in search form

/*echo '<pre>';
print_r($allfields);
echo '</pre>';
*/
?>

<form name="searchall" class="noformpad" style="padding-bottom:5px;" method="POST" action="<?php echo $dadabik_main_file . '?table_name=' . urlencode($table_name) . '&page=0&function=search&execute_search=1'; ?>" enctype="multipart/form-data" accept-charset="Windows-1255" onSubmit="javascript:<?php echo $submitline; ?>return true;">
Quick Search:
<input type="hidden" name="operator" value="or">
<?php echo $allseltypes; ?>
<input name="allterm" type="text" size="10" maxlength="100">
<?php echo $fieldterm; ?>
<input type="submit" value="<?php echo $submit_buttons_ar["search_short"]; ?>" class="submit">
</form>

<?php
} //closing bracket for the if ($_GET["function"] != "show_search_form"
?>

[/pre]
 
Top