...

View Full Version : dropdown box filter problem



myrok
12-17-2008, 09:31 PM
Hi there, 'im having this problem for a long time now and i just can't figure it out with my knowledge of coding..
You can view it here: http://blikvoer.com/temp/samtest/index.php?pagina=portfolio

What i want is to remember the selected category, after clicking in the list.
Also... the "view all" option doesn't give any output..

my code:



<?php if(isset($_POST['select'])){
$category = $_POST['category'];

$query = "SELECT
id, name, label, tekst, datum, category
FROM
upload
WHERE
category = '$category'
ORDER BY
datum DESC

";}
else {
$query = "select id, name, label, tekst, datum from upload ORDER BY datum DESC";
}


$result = mysql_query($query) or die('Error : ' . mysql_error());
?>

<h3> KLANTEN </h3>

<?php
while ($row = mysql_fetch_assoc($result))

{
extract($row);
?>

<ul class="submenu">
<li class="submenu"><a class="submenu" href="index.php?pagina=portfolio&id=<?php echo $id;?>"><? echo $label ?></a></li>
</ul>

<?php
}
?>


The second query maybe not necessary, i added that later..
Please any help..thnx!

logictrap
12-17-2008, 09:42 PM
A few possible ways:

1) use a php session variable to store the selection - will work temporarily
2) use a cookie - will work until the visitor removes cookies

lokeshshettyk
12-18-2008, 08:30 AM
If i were to hard code,


<select name="desiredname">
<option value=""<? if ($_POST['desiredname']=="") { echo " selected"; } ?>>ALL</option>
<option value="3-5"<? if ($_POST['desiredname']=="3-5") { echo " selected"; } ?>>3-5</option>
<option value="6-8"<? if ($_POST['desiredname']=="6-8") { echo " selected"; } ?>>6-8</option>
<option value="9-12"<? if ($_POST['desiredname']=="9-12") { echo " selected"; } ?>>9-12</option>
</select>

And change the code for "ALL" as below


<?
if (empty($_POST['desiredname'])) {
QUERY FOR the "ALL" option
}
else if (isset($_POST['desiredname'])) {
QUERY for the different selections
}
else {
// you any way don't enter this segment
}
?>


Hope this helps

Cheers :)

myrok
12-23-2008, 11:09 AM
I now have the following code:
But somehow it is still jumping back to "all" when i click an item after a selected category..

--> http://blikvoer.com/temp/samtest/index.php?pagina=portfolio




<?php

if(isset($_POST['select']) or isset($_SESSION['category']))
{
if(isset($_POST['select']) )
{
$category = $_POST['category'];
$_SESSION['category'] = $category;
}
else
{
}

$category = $_SESSION['category'];
if($category == 'alles')
{
$where = "";
}
else
{
$where = "WHERE category = '".$category."'";
}

$query = "SELECT
id, name, label, tekst, datum, category
FROM
upload
". $where ."
ORDER BY
datum DESC
";
}
else
{
$query = "SELECT
id, name, label, tekst, datum
FROM upload
ORDER BY
datum DESC";
$category = 'alles';
}

$result = mysql_query($query) or die('Error : ' . mysql_error());
?>
<form method="post">
<select name="category" size="1">
<option value="alles" <?php if($category == 'alles') { echo 'selected="selected"'; } ?>>Alles</option>
<option value="catA" <?php if($category == 'catA"') { echo 'selected="selected"'; } ?>>3-5</option>
<option value="catB" <?php if($category == 'catB"') { echo 'selected="selected"'; } ?>>6-8</option>
<option value="catC" <?php if($category == 'catC"') { echo 'selected="selected"'; } ?>>9-12</option>
</select>
<input type="submit" name="select" value="Toon selectie">
</form>
<h3> KLANTEN </h3>

<?php
while ($row = mysql_fetch_assoc($result))
{
extract($row);
?>
<ul class="submenu">
<li class="submenu"><a class="submenu" href="index.php?pagina=portfolio&amp;id=<?php echo $id;?>"><?php echo $label; ?></a></li>
</ul>
<?php
}
?>

lokeshshettyk
12-23-2008, 11:30 AM
Try this and see what values you get in the select box....

And one more thing if($category == 'catA"') // why is that extra " required????



<select name="category" size="1">
<option value="alles" <?php if($category == 'alles') { echo 'selected="selected"'; } ?>><?=$category;?></option>
<option value="catA" <?php if($category == 'catA') { echo 'selected="selected"'; } ?>><?=$category;?></option>
<option value="catB" <?php if($category == 'catB') { echo 'selected="selected"'; } ?>><?=$category;?></option>
<option value="catC" <?php if($category == 'catC') { echo 'selected="selected"'; } ?>><?=$category;?></option>
</select>
<input type="submit" name="select" value="Toon selectie">



Cheers :)

myrok
12-23-2008, 12:53 PM
im now gettting..
default: all "alles" in dropbox
If a select one: all "catA", or catB etc..

you can see it online (previous post link)

lokeshshettyk
12-23-2008, 03:20 PM
alright,
Now try replacing all the <?=$category;?> with your text, like 3-6, 6-2, 8-12 and so on. It should work fine

Cheers :)

myrok
12-23-2008, 06:21 PM
ok, but then i'am back at the original code?.. or...

lokeshshettyk
12-24-2008, 06:04 AM
Not at all :)

Well, I have even simplified your code and it works all fine on my system.....


<?php
if(isset($_POST['showdata']) || isset($_SESSION['category'])) {
$_SESSION['category'] = $_POST['category'];

if($_SESSION['category'] == 'alles') {
$where = "";
} else {
$where = "WHERE category = '".$_SESSION['category']."'";
}
} else {
$where = "";
}

$query = "SELECT id, name, label, tekst, datum, category
FROM upload ". $where ." ORDER BY datum DESC";
$result = mysql_query($query) or die('Error : ' . mysql_error());
?>

<form method="post">
<select name="category" size="1">
<option value="alles" <?php if($_SESSION['category'] == "alles") { echo 'selected="selected"'; } ?>>Alles</option>
<option value="catA" <?php if($_SESSION['category'] == "catA") { echo 'selected="selected"'; } ?>>3-5</option>
<option value="catB" <?php if($_SESSION['category'] == "catB") { echo 'selected="selected"'; } ?>>6-8</option>
<option value="catC" <?php if($_SESSION['category'] == "catC") { echo 'selected="selected"'; } ?>>9-12</option>
</select>
<input type="submit" name="showdata" value="Toon selectie">
</form>
<h3> KLANTEN </h3>

<?php
while ($row = mysql_fetch_assoc($result))
{
extract($row);
?>
<ul class="submenu">
<li class="submenu"><a class="submenu" href="index.php?pagina=portfolio&amp;id=<?php echo $id;?>"><?php echo $label; ?></a></li>
</ul>
<?php
}
?>

Hope this helps

Cheers :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum