myrok24 Posted December 17, 2008 Share Posted December 17, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/ Share on other sites More sharing options...
Maq Posted December 17, 2008 Share Posted December 17, 2008 You mean - http://blikvoer.com/temp/samtest/index.php?pagina=portfolio ? Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-718174 Share on other sites More sharing options...
myrok24 Posted December 17, 2008 Author Share Posted December 17, 2008 yeah thats the one. --> portfolio Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-718211 Share on other sites More sharing options...
Maq Posted December 17, 2008 Share Posted December 17, 2008 Where does $_POST['select'] and $_POST['category'] come from? I'm guessing another form? Please post all of your code. Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-718243 Share on other sites More sharing options...
myrok24 Posted December 18, 2008 Author Share Posted December 18, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-719014 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 *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>< Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-719041 Share on other sites More sharing options...
myrok24 Posted December 23, 2008 Author Share Posted December 23, 2008 I get an errror: Parse error: syntax error, unexpected T_VARIABLE in xxxx/subnav01.php on line 5 wich is: $category = $_POST['category']; Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-722135 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-722340 Share on other sites More sharing options...
myrok24 Posted December 23, 2008 Author Share Posted December 23, 2008 still fucked up.. Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-722580 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/137439-dropdown-box-filter-problem/#findComment-722599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.