Jump to content

Skormy

New Members
  • Posts

    1
  • Joined

  • Last visited

Skormy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. On my site I have a drop-down menu that allows visitors to sort a widget by a code, let's say color. And that has been working fine. From the same drop-down menu, I would like visitors to be able additionally be able to sort the same widget by the material it is made from. I have been able to get each to work independently, but when I combine them, I believe it defaults to the "else" condition which just shows everything. I have tried to use a specific code for each as well as a generic code for both. The results are the same, displaying all the widgets, not a subset of them. Everything I've tried so far hasn't given me the results I'm looking for. Would love some guidance on how to solve this issue. Thanks. <FORM NAME="sort" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <SELECT NAME="productcode" onchange="this.form.submit();"> <?php $sortcode1 = $_POST['sortcode1']; ?> <OPTION VALUE="ALL"<?php if ($sortcode1=="ALL") { print "selected =\"selected\""; }?>>Display All</option> <OPTION VALUE="E"<?php if ($sortcode1=="E") { print "selected =\"selected\"";} ?>>Display Only Yellow Widgets</option> <OPTION VALUE="P"<?php if ($sortcode1=="P") { print "selected =\"selected\""; }?>>Display Only Purple Widgets</option> <?php $sortcode2 = $_POST['sortcode2']; ?> <OPTION VALUE="CM"<?php if ($sortcode2=="CM") { print "selected =\"selected\""; }?>>Display Only Metal Widgets</option> <OPTION VALUE="FG"<?php if ($sortcode2=="FG") { print "selected =\"selected\""; }?>>Display Only Plastic Widgets</option> </SELECT> <noscript> <input type="submit" name="productcode" value="Display Selected Widgets"> </noscript> </FORM> <?php // database connect stuff $sortcode1 = $_POST['sortcode1']; if ($sortcode1 =="ALL") { $query = "SELECT stuff1,stuff2,stuff3 FROM $db_table WHERE status = 'A' order by stuff1 DESC "; } elseif ($sortcode1 == 'E') { $query = "SELECT stuff1,stuff2,stuff3 FROM $db_table WHERE status = 'A' AND sortcode1 = '$sortcode1' order by stuff1 DESC " ; } elseif ($sortcode1 == 'P') { $query = "SELECT stuff1,stuff2,stuff3 FROM $db_table WHERE status = 'A' AND sortcode1 = '$sortcode1' order by stuff1 DESC " ; } $sortcode2 = $_POST['sortcode2']; elseif ($sortcode2 == 'CM') { $query = "SELECT stuff1,stuff2,stuff3 FROM $db_table WHERE status = 'A' AND sortcode2 = '$sortcode2' order by stuff1 DESC " ; } elseif ($sortcode2 == 'FG') { $query = "SELECT stuff1,stuff2,stuff3 FROM $db_table WHERE status = 'A' AND sortcode2 = '$sortcode2' order by stuff1 DESC " ; } else { $query = "SELECT stuff1,stuff2,stuff3 FROM $db_table WHERE status = 'A' order by stuff1 DESC "; }
×
×
  • 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.