yandoo Posted April 3, 2008 Share Posted April 3, 2008 Hi there, Im having a bit of a nightmare and was hoping for some help please I currently have a simple form with list/menu and options that determine how records in a table are ordered by: <form action="view_food.php" method="get" name="reorder" id="reorder"> <select name="orderby" onchange="if(this.value != '-') document.reorder.submit();"> <option "-">Select one...</option> <option value="FoodID">ID</option> <option value="FoodName">Name</option> <option value="AnimalTypeID">Food Type</option> <option value="Username">User</option> </select> </form> <?php $currentPage = $_SERVER["PHP_SELF"]; if (isset($_GET['orderby'])) { $orderby= $_GET['orderby']; }else{ $orderby="FoodID"; } //CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD ?> mysql_select_db($database_woodside, $woodside); $test= ("SELECT * FROM foods ORDER BY $orderby ASC"); $query_limit_test = sprintf("%s LIMIT %d, %d", $test, $startRow_test1, $maxRows_test1); $test1 = mysql_query($query_limit_test, $woodside) or die(mysql_error()); $result = mysql_query($test) or die(mysql_error()); $row_test = mysql_fetch_assoc($result); $totalRows_test = mysql_num_rows($result); $row_test1 = mysql_fetch_assoc($test1); This all works fine at present, but i Need to add a new option in the list/menu and relate that option to a WHERE clause in my query. This will allow me to find all records WHERE tablefield "CID"= 6 - which is a static number. for example: $test= ("SELECT * FROM foods WHERE CID = 6 ORDER BY $orderby ASC"); <option value="Where clause example">CID number</option> Is it possible to add a WHERE clause to my existing query and present that as an option in the list/menu?? If anybody could please help me that would be great as i'm rather stuck. Thank You Link to comment https://forums.phpfreaks.com/topic/99351-add-where-to-query/ Share on other sites More sharing options...
zenag Posted April 3, 2008 Share Posted April 3, 2008 try this.... <script type="text/javascript"> function gone(form) { var val=form.num.options[form.num.options.selectedIndex].value; self.location=?value=' + val ; } </script> </head> <body><form name="form1" method="get" action="sel.php"> <a href="?num=<? echo $num;?>">ge</a> <select id="num"name="num" onchange="gone(this.form)"><option value="1">1</option><option value="2">2</option></select> </form> </body> </html> <? $value=$_GET["value"]; echo $value; ?> in your code.. ("SELECT * FROM foods WHERE CID = '$value' ORDER BY $orderby ASC"); Link to comment https://forums.phpfreaks.com/topic/99351-add-where-to-query/#findComment-508342 Share on other sites More sharing options...
zenag Posted April 3, 2008 Share Posted April 3, 2008 leave that <a href="?num=<? echo $num;?>">ge</a> its just for testing... Link to comment https://forums.phpfreaks.com/topic/99351-add-where-to-query/#findComment-508349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.