This topic is locked

searching via url

4/5/2010 7:58:57 PM
PHPRunner General questions
M
mdorren author

My customer doesn't want his visitors to be able to search, but want to take them to filtered lists via buttons on his site. I therefore have taken out the left column and all search links in the list. Is there a format that I can use to construct how I want the list to display? For instance:
http://www.mysite.com/data/retbuiltlist.php?stype=1
Thanks

ficcionista 4/7/2010

So far i have found this in PHP Runner's help:
This code is inserted in the visual editor as a PHP Code Snippet on the desired list page.

//create dropdown box

$str = "";

$str.= "<select onchange=\"window.location.href=this.options[this.selectedIndex]. value;\"><option value=\"\">Please select</option>";
//select values from database

global $conn;

$strSQL = "select company from companytable";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

$str.="<option value=\"companytable_list.php?ctlSearchFor=".$data["company"].

"&srchOptShowStatus=1&ctrlTypeComboStatus=0&srchWinShowStatus=0&a=integrated&id=1&criteria=and&type1=&value11=".

$data["company"]."&field1=company&option1=Contains&not1=a=search&value=1\">".$data["company"]."</option>";

$str.="</select>";

echo $str;


I've adapted this piece of code to my needs, mainly changing the query.

I have eight distinct values to search for in my table (2.1, 2.2, 3.1, 4.1, 4.2, 4.3, 4.4 & 4.5), so I created this query:

select distinct(slakpi) as slakpi from reports1


This way the dropdown will only show those eight values.
However I do need another search option: I need to be able to search for every record except those that have SLAKPI = '4.5'.
So far i'm still trying to figure how to do this.

M
mdorren author 4/7/2010



So far i have found this in PHP Runner's help:
This code is inserted in the visual editor as a PHP Code Snippet on the desired list page.

//create dropdown box

$str = "";

$str.= "<select onchange=\"window.location.href=this.options[this.selectedIndex]. value;\"><option value=\"\">Please select</option>";
//select values from database

global $conn;

$strSQL = "select company from companytable";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

$str.="<option value=\"companytable_list.php?ctlSearchFor=".$data["company"].

"&srchOptShowStatus=1&ctrlTypeComboStatus=0&srchWinShowStatus=0&a=integrated&id=1&criteria=and&type1=&value11=".

$data["company"]."&field1=company&option1=Contains&not1=a=search&value=1\">".$data["company"]."</option>";

$str.="</select>";

echo $str;


I've adapted this piece of code to my needs, mainly changing the query.

I have eight distinct values to search for in my table (2.1, 2.2, 3.1, 4.1, 4.2, 4.3, 4.4 & 4.5), so I created this query:

select distinct(slakpi) as slakpi from reports1


This way the dropdown will only show those eight values.
However I do need another search option: I need to be able to search for every record except those that have SLAKPI = '4.5'.
So far i'm still trying to figure how to do this.



Hi ficc,

Thanks for the help.

I WILL try that for another projects but for your (or anyone who's interested" here's what I've discovered:
here's the url format when constructing my links for this project:
http://www.mysite.com/retblresults_list.php?ctlSearchFor=&simpleSrchTypeComboNot=&a=integrated&id=1&criteria=and&type1=&value11=10&field1=Style&option1=Equals&not1=&type2=&value21=1&field2=sType&option2=Equals&not2=
Here's how it works:

we take the ampersands as parameter delimiters like so:
http://www.mysite.com/retblresults_list.php?ctlSearchFor=

&simpleSrchTypeComboNot=

&a=integrated

&id=1

&criteria=and

&type1=

&value11=10

&field1=Style

&option1=Equals

&not1=

&type2=

&value21=1

&field2=sType

&option2=Equals

&not2=
now...

the part of the url that I really care about is:

&criteria=

&type1=

&value11=10

&field1=Style

&option1=Equals

  • "criteria" declare "AND" or "OR"
  • "type1" just means it's the first condition
  • value11 is the value we are looking for in the first condition (in this case 10. In my test search, 10 was the 10th selection in the dropdown)
  • field1 is what field we are looking in for the value (in this case Style)
  • option1 is the kind of condition that we want met (in this case, equals, but it could also be greater than, contains, etc..)
    This have proven to be very helpful to me.
    Once again, thanks for your help.
    Marty

C
chaintm 4/8/2010

Trying to do what is suggested won't work in an insta gratification enviorment, I have no doubt that your client wants to pull down from a list and get instant search done without a box being filled. IE select and bam new page comes up with new related info... To do this you need to do two things. First make your list in your database. This is also very handy when your client would like to add to that list on the fly. Next make a Snippet and use something like the following....
====================================
$str = "";

$str.= "<select onchange=\"window.location.href=this.options[this.selectedIndex].value;\"><option value=\"\">Categories</option>";

$str.="<option value='order_sales_item_list_list.php?a=showall'>Show all</option>";

global $conn;

$strSQL = "select * from items_cat_menu";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

$str.="<option value=\"order_sales_item_list_list.php?ctlSearchFor=&srchOptShowStatus=1&ctrlTypeComboStatus=0&srchWinShowStatus=0&a=integrated&id=1&criteria=and&type1=&value11=".$data["ItemCatID"]."&field1=ItemCatID&option1=Equals&not1=\">

".$data["ItemCatName"]."</option>";

$str.="</select>";

echo $str;
======================================
next add too the list before process the following...
======================================
if (@$_REQUEST["a"] && @$_REQUEST["a"]!="delete" && @$_REQUEST["a"]!="search" && @$_REQUEST["a"]!="advsearch" && @$_REQUEST["a"]!="showall")

{

$arr = explode(",",$_REQUEST["a"]);

if (count($arr)>1)

=====================================
Now the adjustments can be yours of course, the if statements are needed to basicly ignore all request to form a beyond those above to allow the general search to still work after a select is made. The explode of course completes that. The following array if count statement I used to continue on code for other uses, but left it there so you get the idea. This is really the best way I have found to make an interactive pulldown menu that needs customization but also needs to be a select and then generate a new page based on the selected data. If you have any question I will try to stop by again if I have time too, but time is tight latly. GL!
PS. this of course can be used to sort your data on the page (IE hide or show) u can use something like...
if (@$_REQUEST["a"]=="add a panel")

{

$_SESSION["TEMPDATA"] = 2;

header("Location: order_items_add.php?mastertable=order_sales&masterkey1=".$_SESSION[$strTableName."_masterkey1"]);

//=============== carry over values from other tables ===========//
exit();

}
I use a session to pass on a value to the next table, but in this excample, I basicly refilter the add page of a product to the session value and in the field block use @_SESSION["TEMPDATA"] to tell that field the static value (in this instance is 2. You can use this same idea for what you want, session your pulldown based on the value of the pulldown , use the final excample here to sort the page out in the before process on the list page. Again gl, sorry not to be prefectly clear but again figured if you have any coding know how, this will help you in the right direction. salu!

ficcionista 4/26/2010



Trying to do what is suggested won't work in an insta gratification enviorment, I have no doubt that your client wants to pull down from a list and get instant search done without a box being filled. IE select and bam new page comes up with new related info... To do this you need to do two things. First make your list in your database. This is also very handy when your client would like to add to that list on the fly. Next make a Snippet and use something like the following....
(...)


Actually it did work for me. I have in my app a dropdown menu with several choices (queried from the DB. When the user selects one of those choices, bam, a new page comes up with only the records that match the filter chosen.
In my case the list is made from values taken from one specific field in the DB. There are only eight possible values for that field, so the list has eight filters.
P.S. - So far this URL only works in version 5.2, i've tried it in 5.1 and it doesn't work. Since the URLs may be different i'm studying that in order to find out what works in earlier versions of PHPR