156418 Posted September 27, 2006 Share Posted September 27, 2006 Hi Everyone,I'm having a bit of touble with a drop down menu, what I'd like to do it have a drop down menu which shows 5 items:Saturday 9th DecemberSunday 10th DecemberSaturday 16th DecemberSunday 17th DecemberSaturday 23rd Decemberand I'd like to run a slightly different query depending on which one is selected.So for example choosing the first one would run this query and display results:[code]<?php//connect to the database - either incoude a connection variable file or//type the following lines:$connect = mysql_connect ("localhost", "mysqlusername", "mysqlspassword") ordie ("Connection to Database Failed.");mysql_select_db("eventsdb");$query = "SELECT * FROM products WHERE products_eventdate = '2006-12-09'";$results = mysql_query($query) or die(mysql_error());?>[/code]and the 2nd one would run this:[code]<?php//connect to the database - either incoude a connection variable file or//type the following lines:$connect = mysql_connect ("localhost", "mysqlusername", "mysqlspassword") ordie ("Connection to Database Failed.");mysql_select_db("eventsdb");$query = "SELECT * FROM products WHERE products_eventdate = '2006-12-10'";$results = mysql_query($query) or die(mysql_error());?>[/code]Could anyone explain, or point me to a way of doing this? I can only find tutorials so far which populate the drop down from the DB and I dont think I need to be doing that!The queries all work if I setup different pages - so I know that the query is working ok.Many thanks for any help Quote Link to comment Share on other sites More sharing options...
enkidu72 Posted September 27, 2006 Share Posted September 27, 2006 I think a <select> could do it <select name="weekend"><option value="1" >Saturday 9th December</option><option value="2" >Sunday 10th December</option>etc.</select>and then :if ( $weekend == 1 ){ $query="SELECT * FROM products WHERE products_eventdate = '2006-12-09'";}elseif ( $weekend == 2 ){ $query="etc.etc Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 27, 2006 Share Posted September 27, 2006 it is rather simple.. here is an example say you have a form like this[code]<form action="sompage.php" method="post"> <select name="date" size="5"> <option value="whatver">whatever</option> <option value"whatever2">Whatever 2</option> </select><br /> <input type="submit" value="submit" name="submit" /></form>[/code]All you have to do in the file that is defined in the action of the form is this.[code]<?php//connect to the database - either incoude a connection variable file or//type the following lines:$connect = mysql_connect ("localhost", "mysqlusername", "mysqlspassword") ordie ("Connection to Database Failed.");mysql_select_db("eventsdb");$date = mysql_real_escape_string(trim(strip_slashes($_POST['date'])));$query = "SELECT * FROM products WHERE products_eventdate = '$date'";$results = mysql_query($query) or die(mysql_error());//now to display the results do something like this.while ($rw = mysql_fetch_assoc($results)) { //to select a field you start it off with $rw followed by ['theField'] //like this echo 'hello one of your fields is ' . $rw['field'] . ', and another field is ' . $rw['field2'] . '.<br />';}?>[/code]Now you could do the same to display the dropdown box.. like this[code=php:0]echo '<form action="somepage.php" method="post"> <select name="date">';while ($rw = mysql_fetch_array($your_sql_query)) { echo '<option value="' . $rw[''products_eventdate'] . '">' . $rw[''products_eventdate'] . '"</option>';}echo '</select></form>';[/code]Hope that helps,Tom Quote Link to comment Share on other sites More sharing options...
156418 Posted September 27, 2006 Author Share Posted September 27, 2006 Thanks Tom, Looking at it, I think constructed it ok, its just it doesnt like the strip_slashes comment[quote]Fatal error: Call to undefined function: strip_slashes()[/quote]Any ideas to why it would do that, or what I've done to create it![b]Edit - Never mind, I noticed the _ in the function that wasnt needed - seems to be working as expected so far![/b] Quote Link to comment 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.