usadarts Posted August 17, 2006 Share Posted August 17, 2006 I have the following in the header:[code]function categoryHandler(form){var URL = "http://www.Example.com/index.php?"+category.site.value+"=Y";window.location.href = URL;}[/code]The following form in the body:[code] <form name="category"> <div align="center"> <select name="site" size=1 onChange="javascript:categoryHandler()"> <option value=" ">Filter By Category</option> <option value="opt1">Option 1</option> <option value="opt2">Option 2</option> <option value="opt3">Option 3</option> <option value="opt4">Option 4</option> <option value="opt5">Option 5</option> <option value="opt6">Option 6</option> </select> </div> </form>[/code]I then have several IfElse statements to bring up page:[code]if($category == 'opt1') {$query = "SELECT * FROM `links` WHERE `opt1` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());} elseif($category == 'opt2') {$query = "SELECT * FROM `links` WHERE `opt2` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());} elseif($category == 'opt3') {$query = "SELECT * FROM `links` WHERE `opt3` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());} elseif($category == 'opt4') {$query = "SELECT * FROM `links` WHERE `opt4` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());} elseif($category == 'opt5') {$query = "SELECT * FROM `links` WHERE `opt5` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());} elseif($category == 'opt6') {$query = "SELECT * FROM `links` WHERE `opt6` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());}[/code]This does not work. It brings up the URL as:[code]http://www.dartsites.com/index.php?baseball=Y[/code]but does not filter the information as it should. It brings up everything in the database.Any ideas? Link to comment https://forums.phpfreaks.com/topic/17800-php-mysql-help/ Share on other sites More sharing options...
BillyBoB Posted August 17, 2006 Share Posted August 17, 2006 i think it is u have no method to go by like change ur code to ... :[code] <form name="category" method="post"> <div align="center"> <select name="site" size=1 onChange="javascript:categoryHandler()"> <option value=" ">Filter By Category</option> <option value="opt1">Option 1</option> <option value="opt2">Option 2</option> <option value="opt3">Option 3</option> <option value="opt4">Option 4</option> <option value="opt5">Option 5</option> <option value="opt6">Option 6</option> </select> <input type="submit" name="submit" value="Submit" /> </div> </form> <?php if($_POST['submit']) { if($category == 'opt1') { $query = "SELECT * FROM `links` WHERE `opt1` = 'Y' and `approved` = 'Y' ORDER BY `title`"; $result = mysql_query($query,$dbh) or die(mysql_error()); } elseif($category == 'opt2') { $query = "SELECT * FROM `links` WHERE `opt2` = 'Y' and `approved` = 'Y' ORDER BY `title`"; $result = mysql_query($query,$dbh) or die(mysql_error()); } elseif($category == 'opt3') { $query = "SELECT * FROM `links` WHERE `opt3` = 'Y' and `approved` = 'Y' ORDER BY `title`"; $result = mysql_query($query,$dbh) or die(mysql_error()); } elseif($category == 'opt4') { $query = "SELECT * FROM `links` WHERE `opt4` = 'Y' and `approved` = 'Y' ORDER BY `title`"; $result = mysql_query($query,$dbh) or die(mysql_error()); } elseif($category == 'opt5') { $query = "SELECT * FROM `links` WHERE `opt5` = 'Y' and `approved` = 'Y' ORDER BY `title`"; $result = mysql_query($query,$dbh) or die(mysql_error()); } elseif($category == 'opt6') { $query = "SELECT * FROM `links` WHERE `opt6` = 'Y' and `approved` = 'Y' ORDER BY `title`"; $result = mysql_query($query,$dbh) or die(mysql_error()); } }[/code] Link to comment https://forums.phpfreaks.com/topic/17800-php-mysql-help/#findComment-76021 Share on other sites More sharing options...
usadarts Posted August 17, 2006 Author Share Posted August 17, 2006 That can't be it. I have other drop down menu's to help filter information and they all work but this one. Thank though Link to comment https://forums.phpfreaks.com/topic/17800-php-mysql-help/#findComment-76022 Share on other sites More sharing options...
Jeremysr Posted August 17, 2006 Share Posted August 17, 2006 Change all the if($category to if($site Link to comment https://forums.phpfreaks.com/topic/17800-php-mysql-help/#findComment-76023 Share on other sites More sharing options...
BillyBoB Posted August 17, 2006 Share Posted August 17, 2006 well sorry i couldnt help but Jeremysr got it im just not that good with code thats not my own Link to comment https://forums.phpfreaks.com/topic/17800-php-mysql-help/#findComment-76027 Share on other sites More sharing options...
trq Posted August 17, 2006 Share Posted August 17, 2006 It should actually be...[code=php:0]if ($_GET['site'][/code] Link to comment https://forums.phpfreaks.com/topic/17800-php-mysql-help/#findComment-76035 Share on other sites More sharing options...
usadarts Posted August 23, 2006 Author Share Posted August 23, 2006 I now have the following and it still does not work[code]function categoryHandler(form){var URL = "http://www.TestURL.com/index.php?"+category.site.value+"=Y";window.location.href = URL;}[/code][code] <form name="category"> <div align="center"> <select name="site" size=1 onChange="javascript:categoryHandler()"> <option value=" ">Filter By Category</option> <option value="opt1">option 1</option> <option value="opt2">option 2</option> <option value="opt3">option 3</option> </select> </div> </form>[/code][code]if($_GET['site'] == 'opt1') {$query = "SELECT * FROM `links` WHERE `opt1` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());} elseif($_GET['site'] == 'opt2') {$query = "SELECT * FROM `links` WHERE `opt2` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());} elseif($_GET['site'] == 'opt3') {$query = "SELECT * FROM `links` WHERE `opt3` = 'Y' and `approved` = 'Y' ORDER BY `title`";$result = mysql_query($query,$dbh) or die(mysql_error());}[/code]Still not working....still show all links instead of the selection I want. Thanks above for all the help so far......David Link to comment https://forums.phpfreaks.com/topic/17800-php-mysql-help/#findComment-78993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.