This topic is locked

Filter Combobox for new url filtering mode

5/18/2016 1:13:20 AM
PHPRunner General questions
C
carlos.oschi@gmail.com author

Hi everyone...
i need a filter list with some values over my personalizated session... so the main idea is
this is another version of your own list box for search
a) add php snippet in the place of your preference.
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=23856&image=1&table=forumtopics' class='bbc_emoticon' alt='B)' /> add the next code.
$str= "<select onchange=\"window.location.href=this.options[this."."selectedIndex].value;\"><option value=\"\">Seleccione</option>";
// this get the filter mode q variable on the page parameters, i need only the year of some variable so, get the string and parse it for my own

// bla bla bla ... list.php?q=(ano~equals~2016)

// so get q variable
$ano = $_GET["q"];

$ano = substr($ano,strlen($ano)-5,4);
global $conn;

$strSQL = "select distinct ano from anos_usuario where usuario_ID = ".$_SESSION['usuario_ID'];

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

while ($data = db_fetch_array($rs))

{
// put attention here, my var $ano is compared with the database value and mark if the selected

// this is because the code makes a refresh of the page, so the value selected is lost in this step

// the workarround is get the value in $_GET variable and use it
if ($data["ano"]==$ano) $selected = " selected"; else $selected = " ";
$str.="<option value='table_list.php?q=(ano~equals~".$data["ano"].")' ".$selected." >".$data["ano"]."</option>";

}

$str.="</select>";

echo $str;
this solution doesn't need a javascript.
best regards

Carlos.