This topic is locked
[SOLVED]

 multiple dropdown boxes to filter _list.page

9/6/2011 10:15:03 AM
PHPRunner General questions
Y
YCH author

Hello.
I've been consulting this forum some time now but never posted a question as yet.

But here I start.
I have a _list.php with business addresses (table = BA) and other items.

I inserted a php_snippet in the _list.php with 3 dropdown boxes with values from 3 different tables (none of which being the _list.page table)

I would like to dynamically filter the _list.page based on the values selected in those 3 dropdown boxes.
I have this code yet: **
$str1 = "";

$str1.="<select size=3 name=\"criteria1\" id=\"criteria1\"><option value=\"\">pcode</option>";
$str2 = "";

$str2.="<select size=3 name=\"criteria2\" id=\"criteria2\"><option value=\"\">lease_sale</option>";
$str3 = "";

$str3.="<select size=3 name=\"criteria3\" id=\"criteria3\"><option value=\"\">off_ind</option>";
//

global $conn;
$strSQL1 = "select distinct check1 from table1";

$rs1 = db_query($strSQL1,$conn);

while ($data = db_fetch_array($rs1))

$str1.="<option value=".$data['check1'].">".$data['check1']."</option>";

$str1.="</select>";
$strSQL2 = "select distinct check2 from table2";

$rs2 = db_query($strSQL2,$conn);

while ($data = db_fetch_array($rs2))

$str2.="<option value=".$data['check2'].">".$data['check2']."</option>";

$str2.="</select>";
$strSQL3 = "select distinct check3 from table3";

$rs3 = db_query($strSQL3,$conn);

while ($data = db_fetch_array($rs3))

$str3.="<option value=".$data['check3'].">".$data['check3']."</option>";

$str3.="</select>";
// form

echo '<form action='.$_SERVER["PHPSELF"].' method="post">';
echo $str1."
".$str2."".$str3."";
echo '<input type="submit" name="submit" value="continue" />';

echo '</form>';
if (isset($_POST['submit']))

{

$_SESSION["crit1"] = $_POST['criteria1'];

$_SESSION["crit2"] = $_POST['criteria2'];

$_SESSION["crit3"] = $_POST['criteria3'];
}
$strWhereClause = "BA_field1=".$_SESSION["crit1"]." and " . "BA_field2 =".$_SESSION["crit2"]." and ". "BA_field3 =".$_SESSION["crit3"];
[color="#006400"]// Who can help me further with this ?

Many thanks.

Sergey Kornilov admin 9/7/2011

I'm not sure what kind of help you looking for. Are you getting any errors? Where are you with this right now?

Y
YCH author 9/7/2011

Sergey,
How do I continue with this? How do I refresh my _list.page based on the triple selection made?

What is the coding that I need to write and where do I put it?
many thanks in advance for yopur advice.

Y
YCH author 9/7/2011

Sergey,
I have given some additional thought and came with this.

I have changed - simplified the coding from here on
))

{

$_SESSION["selection"] = ' ZipCode='.$_POST['criteria1'].' and PropLSE="'.$_POST['criteria2'].'" and PropType="'.$_POST['criteria3'].'"';

}
Then I requery/filter the _list.page by adding this line in the Before SQL Query event tab on the _list.page
If hardcoded everything goes well like:
$_SESSION["selection"] = ' ZipCode=9000 and PropLSE="L" and PropType="I" '
but not with this code :

[color="#006400"]$_SESSION["selection"] = ' ZipCode='.$_POST['criteria1'].' and PropLSE="'.$_POST['criteria2'].'" and PropType="'.$_POST['criteria3'].'"';
So the overall picture is --> on first _list.page shows all the records.

  • Then on selecting the values from the dropdown boxes and submitting nothing seems to happen (all records show)

    * then on reselecting the values and resubmitting --> the _list.page is being filtered as expected !!!
    Then on making a NEW selection from the dropdown boxes and resubmitting we have the same problems as in


    then on reselecting the same values and resubmitting -->the _list.page is being filtered as expected !!!
    Please who can help with the last bits and pieces ?

Y
YCH author 9/7/2011

I have tried some more .

The coding below should not be in the 'php snippet event' on the _list.php page but in the Before_SQL_query event.
if (isset($_POST['submit']))

{

$_SESSION["selection"] = ' ZipCode='.$_POST['criteria1'].' and PropLSE="'.$_POST['criteria2'].'" and PropType="'.$_POST['criteria3'].'"';

}
together with
$strWhereClause=$_SESSION["selection"];
Then I elaborated further on with this code having this result finally:
if (isset($_POST['submit']))

{
$_SESSION["selection"] ="";
// 1

if ($_POST['criteria1']!=""){

$_SESSION["selection"].= 'ZipCode="'.$_POST['criteria1'].'"';

echo "
".$_SESSION["selection"];

}

else

{

echo "
".$_SESSION["selection"];

}
// 2

if ($_POST['criteria2']!="")

{

if ($_SESSION["selection"]!=""){

$_SESSION["selection"].= ' and PropLSE="'.$_POST['criteria2'].'"';

echo "
".$_SESSION["selection"];

}

if ($_SESSION["selection"]==""){

$_SESSION["selection"].= 'PropLSE="'.$_POST['criteria2'].'"';

echo "
".$_SESSION["selection"];

}

}
// 3

if ($_POST['criteria3']!="")

{

if ($_SESSION["selection"]!=""){

$_SESSION["selection"].= ' and PropType="'.$_POST['criteria3'].'"';

echo "
".$_SESSION["selection"];

}

if ($_SESSION["selection"]==""){

$_SESSION["selection"].= 'PropType="'.$_POST['criteria3'].'"';

echo "
".$_SESSION["selection"];

}

}
}
$strWhereClause=$_SESSION["selection"];
Now everything works fine.
But who can help me further with the next additional step --> meaning being able to select multiple values per dropdown box and combining the results in the selection query.

Sergey Kornilov admin 9/7/2011

YCH,
sorry, still not clear what kind of help is required.
If you have a current support account post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program. Once we see this code in action we'll be able to assist.