Jump to content

dropdown box filter problem


myrok24

Recommended Posts

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/ind...gina=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!

Link to comment
https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/
Share on other sites

whole code:

 

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
?>

<style type="text/css"> <!--
a.submenu {font-size:11px;	font-family: verdana;}
a.submenu:hover{background-color:#F63;}
ul.submenu{ margin:0px;padding-left:20px; line-height:0.7em; list-style-type: square;}
li.submenu {margin:0px;font-size:0.7em; text-align:left;}
--></style>



<form method="post">
  <select name="category" size="1">
   <option value=category selected="selected">Alles</option>
    <option value="catA">3-5</option> 
    <option value="catB">6-8</option> 
    <option value="catC">9-12</option> 
  </select>
  <input type="submit" name="select" value="Toon selectie"> 
</form> 


<?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 
}
?>

</body>
</html>


*NOT TESTED

 

This should remember the selection from the drop down menu.  All you do is create an associative array with the values from the drop down and use the POST method to find out which one was SELECTED and assign it a string "SELECTED".

 

ini_set('display_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['select'])){
$category = $_POST['category'];
$selected[$category] = " SELECTED";
$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());
?>

 KLANTEN 

while ($row = mysql_fetch_assoc($result)) {
extract($row);   
?>
      </pre>
<form method="post">
  
   Alles
    >3-5
    >6-8
    >9-12
  
  
</form>
<br><br>      <ul class="submenu">
       echo $label; ?>
      </ul>
<br>      <br>}<br>?><br><br><br><

You need to submit somewhere with the action variable.  Since you're submitting to the same page use this:

 

</pre>
<form method="post" action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>"><

 

Your error usually mean there is some format issue, like missing a semi colon.  Try replacing the line above and see if it works.

still fucked up..

 

What does that mean?  Is it returning anything?  Are there errors?

 

You need to learn basic HTML & PHP...

 

Try this:

 

ini_set('display_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['select'])){
   $category = $_POST['category'];
   $selected[$category] = " SELECTED";
   $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());
?>



 KLANTEN 

      </pre>
<form method="post" action="<?php%20echo%20%24_SERVER%5B'PHP_SEFL'%5D;%20?>">
  
   Alles
    >3-5
    >6-8
    >9-12
  
  
</form>
<br><br><br>while ($row = mysql_fetch_array($result)) { <br>?><br>      <ul class="submenu">
       echo $row['$label']; ?>
      </ul>
<br>     <br>}<br>?><br><b

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.