Hi pbötcher,
as promised, I report back.
Your solution is great. Thank you very much.
For the interested reader:
I noticed though, that when searching from the table view, only the containercode column is being searched. I think you might have missed an equal sign in the if. Also post variables TV and DV are (imho) not always set as expected: TV for example is (of course) not set when you click on the navigation menu link or you click on the title, but when you submit the search on the TV. Also that post stays fixed until started from the details page....
Anyways, I was able to fix those little nasty not-as-supposed-to things. I introduced another hidden field into the js and changed the php a little.
In tablename-dv.js:
Code: Select all
$j(function() {
$j('h1').addClass('col-sm-8');
$j('h1').after('<h1 class="col-sm-4">\
<form id="form_search" action="TABLENAME_view.php" method="post">\
<div class="input-group" id="quick-search">\
<input type="text" id="SearchString" name="SearchString" class="form-control" placeholder="Search">\
<span class="input-group-btn">\
<button name="Search_now" value="1" id="Search_now" type="submit" class="btn btn-default" title="Search">\
<i class="glyphicon glyphicon-search"></i>\
</button></span></div>\
<input type="hidden" id="DetailsViewSearch" name="DetailsViewSearch" value="1"></form></h1>');
})
and in tablename _init function
Code: Select all
if (!empty($_POST['SearchString']) && $_POST['DetailsViewSearch']=='1' ) {
$save_quicksearch = makeSafe($_POST['SearchString']);
$res = sql("SELECT * from TABLENAME where FIELDTOSEARCH like '%".$save_quicksearch ."%'",$eo);
$_POST = array(); //clear search
if (db_num_rows($res) == 1) {
$row = db_fetch_assoc($res);
redirect("TABLENAME_view.php?SelectedID=".$row['TABLE_PK']);
exit;
}
}
It
looks like this:
- ec202003_new_searchfield.png (11.14 KiB) Viewed 16477 times
And it
behaves like this:
If something is searched on the TABLE view: Results are shown at the table view, just normal (even if only 1 hit). All columns of the table view are searched.
If something is searched on the DETAIL view (search is done as
contains: %searchterm% ) :
a) No hits -> show table view with "no hits"
b) exactly ONE hit -> one the record that has been found.
c) multiple records are found (e.g. only a part of the searched string was entered and that occurs in multiple records): results are shown at the table view, just normal
Perfect. Again pbötcher, thank you very much!
Olaf