Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dropdown box filter problem

    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 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!

  • #2
    Regular Coder logictrap's Avatar
    Join Date
    Apr 2008
    Posts
    155
    Thanks
    11
    Thanked 3 Times in 3 Posts
    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

    Which came first - the chicken or the egg? The egg... [ticket closed]
    If a tree falls... does it make a sound? Yes.............. [ticket closed]

  • #3
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    If i were to hard code,
    PHP 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
    PHP Code:
    <?
    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
    Last edited by lokeshshettyk; 12-18-2008 at 08:33 AM.

  • #4
    New Coder
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/ind...gina=portfolio

    PHP Code:

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

    ?>
    Last edited by myrok; 12-23-2008 at 11:13 AM.

  • #5
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Try this and see what values you get in the select box....

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

    PHP Code:
     <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

  • #6
    New Coder
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

  • #7
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    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

  • #8
    New Coder
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, but then i'am back at the original code?.. or...

  • #9
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Not at all

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

    PHP Code:
    <?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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •