PHP - Dynamic Multiple Drop Downs Help
I have attempted to get a php reporting page built for our off site managers to run reports. Because of the number of employees I think it ouwld be best to sort by foreman, then be able to pick from the resulting drop down list of current employees under that foreman.
My issue I think really comes from having the first drop down be dynamic in that you would see a list of foremen which comes from a query of the main employees table and then picks up only active employees and their foreman. The tutorials I have seen all reference an 'id" field but since I am pulling the info for the drop down from a query, should I have some sort of rowID? If so how? The tutorial I have found checks to see if you pick a number which I seem to have gotten around but when I do the query and look for $GF (general foreman) then the query comes back empty (this is bolded and underlined below). Should this be some sort of rowID for the general foreman drop down?
Below is what I have been able to sort-of get working (adding in the URL handlers I think will be useful for people in the future to be able to bookmark it/send out emails with links already in it etc)
Here is the tutorial http://www.plus2net....p_down_list.php
Not sure if i understand why he used the $nocitia tags either
I know Im close on this but am starting to go crosseyed! Thanks for pointing me in the right direction.
<?php require 'config.php'; // Database connection //////// End of connecting to database //////// ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple drop down list box</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.GF.options[form.GF.options.selectedIndex].value; var val2=form.EMPLOYEE_ID.options[form.EMPLOYEE_ID.options.selectedIndex].value; var val3=form.SEPARATED.options[form.SEPARATED.options.selectedIndex].value; self.location='dd3.php?GF=' + val + '&EMPLOYEE_ID=' + val2 + '&SEPARATED=' + val3 ; } </script> </head> <body> <?Php @$GF=$_GET['GF']; // Use this line or below line if register_global is off @$EMPLOYEE_ID=$_GET['EMPLOYEE_ID']; // Use this line or below line if register_global is off @$SEPARATED=$_GET['SEPARATED']; // Use this line or below line if register_global is off ///////// Getting the data from Mysql table for first list box////////// $quer2="SELECT tbl_Employee_Master.Current_GF as GF FROM tbl_Employee_Master GROUP BY tbl_Employee_Master.Current_GF, tbl_Employee_Master.Separated HAVING (((tbl_Employee_Master.Separated)=0))"; ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// if(strlen($GF) > 0){ $quer="SELECT Employee_ID tbl_Employee_Master WHERE Current_GF=$GF"; }else{$quer="SELECT DISTINCT Employee_ID, Last_Name, First_Name FROM tbl_Employee_Master order by Last_Name"; } ////////// end of query for second subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='dd-check.php'>"; /// Add your form processing page address to action in above line. Example action=dd-check.php//// ////////// Starting of first drop downlist ///////// echo "<select name='GF' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; foreach ($dbo->query($quer2) as $noticia2) { if($noticia2['GF']==@$GF){echo "<option selected value='$noticia2[GF]'>$noticia2[GF]</option>"."<BR>";} else{echo "<option value='$noticia2[GF]'>$noticia2[GF]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='EMPLOYEE_ID'><option value=''>Select one</option>"; foreach ($dbo->query($quer) as $noticia) { echo "<option value='$noticia[Employee_ID]'>$noticia[Employee_ID] $noticia[Last_Name] $noticia[First_Name]</option>"; } echo "</select>"; ////////////////// This will end the second drop down list /////////// //// Add your other form fields as needed here///// echo "<input type=submit value=Submit>"; echo "</form>"; ?> <br><br> <a href=dd.php>Reset and start again</a> <br><br> <center><a href='http://www.plus2net.com' rel="nofollow">PHP SQL HTML free tutorials and scripts</a></center> </body> </html> Similar Tutorialshii,everyone... i am new to the forum ..so forgive me if i make some errors in describing my problem i want to create a drop down menu...the values of which i want to retrieve from a table i have created in my database... i have been able to acheive this...but i want a second drop down menu...in which i want the values to get filtered according to the selection of the first drop down menu... i hav a table with the name test...which i am connecting to the first drop down menu i hav created another table with the name testtype...for second menu.. the id of first table is the testid of second... plzz help me with creating the second menu... my code is Code: [Select] <?php $sql_result = "select test_series FROM test"; $result = mysql_query($sql_result); ?> <td>Select Test Series </td> <td> <select name="testseries" id="testseries" )"> <option>Select</option> <?php if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $test = $row['test_series'];?> <option><?php echo $test ?></option> <?php } } else {?> <option>No Names Present</option>"; <?php } ?> </select> </td> </tr> <tr> <?php $testseries = $_POST['testseries']; $query = "select id from test where test_series = '$testseries'"; $resultt = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($resultt); $id = $row['id']; $sql_result = "select test_name FROM testtype where testid = $id"; $result = mysql_query($sql_result); ?> <td>Select Test Name </td> <td> <select name="testtype"> <option>Select</option> <?php if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $test2 = $row['test_name'];?> <option><?php echo $test2 ?></option> <?php } } else {?> <option>No Names Present</option>"; <?php } ?> </select> </td> </tr> IN THIS CODE I AM GETTIN AN ERROR Undefined index: testseries in ..addques.php on line 155 WHICH IS THIS ONE $testseries = $_POST['testseries']; I am using the following code to generate a dynamic drop down menu from a column in table1(name) - and then inserting the selected option into table2. What I am trying to do is, select data from 2 columns from table1(name,age) and then store and insert both of those values into table2 I am hoping someone can help me out or at least point me in the rigth direction. ..I would like to insert into table 2 the age that matches the person selected by the drop down menu from table1. For example - if from the drop down menu I choose John - when the form is sumbitted i want to insert into table2 John's name and age (based on what is stored in table1, in this case John,22) ...Any ideas??? table1 id|name|age|score 01-john-22-1547 02-jane-22-1245 table2 id|county|name|age the dynamic drop down is generated from table1 (name) with following code Code: [Select] <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table width="100%" border="0" cellpadding="5" cellspacing="0"> <?php require_once('sql.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query="SELECT name FROM table1 ORDER BY name ASC"; $result = mysqli_query ($dbc,$query) or die(mysqli_error()); $dropdown = "<select name='name'>"; while($row = mysqli_fetch_array($result)) { $dropdown .= "\r\n<option value='{$row['name']}'>{$row['name']}</option>"; } $dropdown .= "\r\n</select>"; echo $dropdown; ?> <tr> <td height="50" align="right"> <label for="scheduled_time">Country</label><br/> </td> <td align="left"> <input type="text" id="country" name="country" class="input" maxlength="30"" /> </td> </table> <p></p> <input type="submit" value="Add Info" name="submit" /> </form> I am inserting into table2 with the following code Code: [Select] <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { $county = mysqli_real_escape_string($dbc, trim($_POST['country'])); $name = mysqli_real_escape_string($dbc, trim($_POST['name'])); $query = "INSERT INTO table2 (country, name) VALUES ('$country', '$name'')"; $result = mysqli_query($dbc, $query); if (!$result) { printf("query error : <br/> %s\n", mysqli_error($dbc)); } if ($result) { echo 'Success'; } // close dbc mysqli_close($dbc); exit(); } ?> A form on my website uses several drop down boxes. One to select an id number from a list retrived by a query. The others to get a start and stop time. Using two for each, one for hours, one for minutes. I already have some validation code which works fine, however, I can't seem to be able to use > or < mathematical signs with the times (ie, the start time must be < than the stop time). Also, I have Code: [Select] value="<? echo $name; ?>" in each of the fields to re-insert the data as it gets erased if the form isn't correct. How do I do the same for the drop downs? I hope this makes sense. Code: [Select] <? // only validate form when form is submitted if(isset($Submit)){ $error_msg=''; if(trim($starttime)==(trim($stopttime))) { //drop down $error_msg.="starttime cannot equal stop time.<br>"; } if(trim($starttime)>(trim($stopttime))) { //drop down $error_msg.="starttime cannot be greater than stop time.<br>"; } if(trim($startfuel)<(trim($stopfuel))) { //text field $error_msg.="Departure fuel cannot be less than arrival fuel<br>"; } if(trim($id)=="sca") { //query powered drop down (this one works, but doesn't re-select the option $error_msg.="Please select the id number.<br>"; } http://southerncrossairlines.ausvirtual.com/New%20Site/Complete/validation/Untitled-1.php Hello, I need help filtering an SQL query based on the combination of drop down menus. I have tried using this code found in another thread but I am still getting all rows selected. Any ideas?? Thank you. Here is my html Code: [Select] <form name="xml.php" method="POST"> <input type="button" id="showmarkers" value="Show Markers" /> <select name="meetingType"> <option value="All Types" selected="All Types">All Types</option> <option value="fun">fun</option> <option value="work">work</option> </select> <select name="meetingDay"> <option value="All Days" selected="All Days">All Days</option> <option value="Monday">Monday</option> <option value="Tuesday">Tuesday</option> <option value="Wednesday">Wednesday</option> <option value="Thursday">Thursday</option> <option value="Friday">Friday</option> <option value="Saturday">Saturday</option> <option value="Sunday">Sunday</option> </select> <select name="meetingTime"> <option value="All Times" selected="All Times">All Times</option> <option value="Early">Early</option> <option value="Noon">Noon</option> <option value="Late">Late</option> </select> </form> And the PHP: Code: [Select] $whereClauses = array(); if (! empty($_POST['meetingType'])) $whereClauses[] ="meetingType='".mysql_real_escape_string($_POST['meetingType'])."'"; if (! empty($_POST['meetingDay'])) $whereClauses[] ="meetingDay='".mysql_real_escape_string($_POST['meetingDay'])."'"; if (! empty($_POST['meetingTime'])) $whereClauses[] ="meetingTime='".mysql_real_escape_string($_POST['meetingTime'])."'"; $where = ''; if (count($whereClauses) > 0) { $where = ' WHERE '.implode(' AND ',$whereClauses); } $resultID = mysql_query("SELECT * FROM meetings".$where); Hi All, I'm quite new to this PHP stuff and have been creating a site just for the hell of it really but i have a rather bizarre problem that has been driving me nuts for about a week... I have two drops downs, the first gives a list of teams from a mysql table and then this populates the next drop down with a list of players from the selected team.. so far so good. When I hit the select/submit button to select the player, what should happen is both the "team" and "player" are put into another query which gives the stats on the selected player for all the games that he has played in. however, what actually happens in the Session variable sets the "team" variable to blank. I can see this happening when I use Print_r ($_SESSION); So essentially when I click on either submit button from my drop down forms the other value is being removed from the Session array. Oh, the session is still valid (not being destroyed and replaced with another session). First drop down $query_teams="select Team from $teams"; $team_result=mysql_query($query_teams); $num_team=mysql_numrows($team_result); echo $num_team; print_r ($row_team); $team_count = 0; echo '<form method="post" action="map_selector.php">'; echo "<SELECT name='country'>"; while ($row_team1 = mysql_fetch_assoc($team_result)) { $team_info = $row_team1["Team"]; echo "<OPTION value='$team_info'>$team_info </option>"; } echo '</select>'; echo '<center><input type="submit" value="Search"></center>'; $country = $_POST["country"]; $_SESSION["country"] = $country; echo '</form>'; So SCOTLAND is selected Some sql queries to get the results for the possible players and then Drop down 2 $row_full = array_unique($row_home); echo '<form method="post" action="map_selector.php">'; echo "<SELECT name='Player'>"; foreach ($row_full as $key => $value) { echo "<OPTION value='$value'> $value"; } echo '</select>'; echo "@"; echo $country; echo "@"; echo '<center><input type="submit" value="Search"></center>'; $country=$_POST["country"]; $player=$_POST["Player"]; echo "#"; echo $country; echo "#"; echo '</form>'; $_SESSION["Player"] = $player; $selected_player = $_SESSION["Player"]; echo $player; echo $selected_player; echo $country; Print_r ($_SESSION); so Print_r ($_Session) returns: Array ( [Player] => [country] => Scotland [] => ) then a player "Paul Hartley" is selected from the player list and submit is click and then Print_r($_Session) shows: Array ( [Player] => Paul Hartley [country] => [] => ) Can anyone please help... I just can;t understand why this is happening when I'm using a Sessions which, I thought, would retain all variable values until a time-out or a destroy Thanks nhsal69 Holy smoke, it has been a looooooong time since I have been here. Love the new look of the site btw. Well I am working on a new project for my church. The idea is an email to SMS program. So one use of this would be that if there is a youth activity I could send a message to the entire youth group with one message. I am trying to figure out something specific with it. I need to create a form that grabs info from the database. So more specifically what I need is one drop down that will have "Youth Group", "Parents", "Deacons", etc. now based on what I select I need the second drop down to populate with the corresponding people in that group. Now I want an "All" to be in the drop down to which would let me send the message I type to ALL people in the desired group but to also have the individual names come up just in case I need to do a specific person. How would I go about doing something like this? I have done much research and cant quite find what I would need to do. Any help would be GREATLY appreciated. I am a beginner. How do you capture the selected value in dynamic dropdown and submit it to a different table in mysql I really can't get my head around this dynamic drop box. What I want is for a drop box to be populated with values in my database. I have this that connects to my SQL and picks out the table required: function displayUsers(){ global $database; $q = "SELECT username," ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); ... I then have this to pick out any errors, and also using the num_rows to get the number of rows (values) there a $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } From here, I guess I want the num_rows to keep 'adding on' the number of <option value=""> in my selection box according the number of values I have in my database. At this point, I can pull out the values into a dynamic table ... but I want it into a drop box -- but I'll but up the code for the dynamic table so you can get an idea: /* Display table contents */ echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td></tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); echo "<tr><td>$uname</td></tr>\n"; } echo "</table><br>\n"; } I hope you can use the code above to help me develop this darn drop box! Thanks, Ollie! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306771.0 Hi, Can anyone point me in the right direction please? I want to have a drop down box which when a user clicks on a category the results on the page have changed to show only the data which is relative to the category chosen by the user. I also need a way so that when they click view all they are able to see all the results again. Not really sure what to look for or even how hard this might be. Lee i have created a seating system. based on the number of seats booked that value is passed to a page that dynamicly produces a drop down box for each seat booked so the type of seat price can be assigned. this part works fine. the problem i have is how do i code the recieving page not knowing how many values are going to be passed? this is the drop down menu page Thanks Code: [Select] <form action="payment.php?seatco=<?php echo $s_count; ?>" method="post" name="f1"> <div id="tick_select"> <?php for($i=1; $i<=$s_count; $i++){ $tick= mysql_query("select * from ticket_list"); ?> <select name="tick_com<?php echo $i; ?>" id="tick_com" onChange="" title="Choose A Ticket"> <option value="">Select Ticket type</option> <?php while($result= mysql_fetch_assoc($tick)) { ?> <?php echo '<option value="'.$result[ticket_id].'" name="'.$result[price].'">'.$result[type].'</option>';?> <?php }}?> </select> </div> <INPUT TYPE="submit" VALUE="Select"> </form> Hey Guys, I'm building a site and I need a drop down menu created dynamicly.... This is the flat html code Code: [Select] <div class="art-nav"> <div class="l"></div> <div class="r"></div> <ul class="art-menu"> <li><a href="URL 1"><span class="l"></span><span class="r"></span><span class="t">TOP LEVEL</span></a> <ul> <li><a href="URL 1">SUB CAT 1</a></li> <li><a href="URL 2">SUB CAT 2</a></li> <li><a href="URL 3">SUB CAT 3</a></li> </ul> </li> <li class="art-menu-li-separator"><span class="art-menu-separator"></span></li> <li><a href="URL 5"><span class="l"></span><span class="r"></span><span class="t">Contact Us</span></a></li> </ul> </div> This is the code that shows a dyamic code, but not in the menu... <?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?> <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link"><?php wpsc_print_category_name();?></a> | <?php wpsc_print_subcategory(); ?> <?php wpsc_end_category_query(); ?> Hi guys, I'm still not having any luck with coming up with an idea of how to make my multi-level drop down menu work with items from a database. I don't necessarily need code, but an idea of how to make it work, so any ideas are welcome. The table: Column Descriptions: id - The unique id label - The text to display link - The link to be used relation - I cannot remember why I wanted that... just disregard it parent - The parent item's id (0 for no parent) sort - A sort number for the item (ascending) active - 0 for false, 1 for true (not implemented yet, will add a WHERE `active` = 1 into the sql later) depth - How many parent items there are Now, here's what it has to do (the class): Grab items from the database (sorted by depth, parent, and sort) Place the children in a child array of the parents (or however it can be sorted) Implode the array and turn it into an html menu with the below structure Menu HTML Structure Code: [Select] <div id="menu"> <ul> <li><h2>Level 1 A</h2> <ul> <li><a href="?r=level2/a">Level 2 A</a> <ul> <li><a href="?r=level3/a">Level 3 A</a></li> <li><a href="?r=level3/b">Level 3 B</a></li> </ul> </li> </ul> </li> <li><a href="?r=level1/b"><h2>Level 1 B</h2></a></li> </ul> </div> And here is the code I have so far, but I can't figure out how to get the children into the parent array, or at least sort it so that I can achieve the above HTML structure. Thank you in advance for your help, and as I said above, I don't necessarily need code, but an idea of how to make it work, so any ideas are welcome. Hello,, I have looked for numerous examples, and have only got part of the answer. I have successfully populated a drop down list by reading the database. It populates with a list of quest titles. Once the user selects the quest. I want a textbox to populate with the Quest Description. I found an example that uses AJAX/PHP to do this, but it doesn't access a db to read/populate. The main code is in index.html The original example you select a country, and it populates a text field with the currency code. It passes a variable called $country to another file called find_ccode.php. I changed the first case in find_ccode.php to access my database, and populate the text box with quest description. Ideally I will like to make this case dynamic based off QuestID, would populate textbox with corresponding Quest Description (QDescrip). I then tried the other way in index.php I dynamically populated the dropdown list, and gave the option values the QuestIDs to be passed to $country, but something isn't working. I have a write files command to let me know what the $country variable is passing, and it never writes. It works in index.html though. I apologize in advance for my amateurish coding. I still have a lot to learn. I have included the code below, but if you know a more elegant way of doing it. I am creating a role-playing game, as you probably have figured out by now. I hope to one day put it on the web, but right now using it as a way of learning html, and PHP. I really want to know how to catch the value of the dropdown box. I would like to know what it is before sending over. also what is this.value. I assume this is what the value of the dropdown box is when you have selected something. I have been beating my head for days trying to figure this out. Any help is very much appreciated! Index.html <html> <head> <title>Changing textbox value based on dropdown list using Ajax and PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use //fuction to return the xml http object function getXMLHTTP() { var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCurrencyCode(strURL) { var req = getXMLHTTP(); if (req) { //function to be called when state is changed req.onreadystatechange = function() { //when state is completed i.e 4 if (req.readyState == 4) { // only if http status is "OK" if (req.status == 200) { document.getElementById('cur_code').value=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;"> <form style="text-align:center" method="post" action="" name="form1"> <p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p> <p>Country : <select name="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)" <?php mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query('select QuestID,QTitle, QDescrip from QuestList'); $options=""; while ($row=mysql_fetch_array($result)) { $QuestID=$row["QuestID"]; $QTitle=$row["QTitle"]; $options.="<OPTION VALUE=\"$QuestID\">".$QTitle; } ?> <option value="">Select Country</option> <option value="1">USA</option> <option value="2">UK</option> <option value="3">Nepal</option> </select><br/><br/> Currency : <input type="text" name="cur_code" id="cur_code" ></p> </form> </body> </html> Index.php <html> <head> <title>Changing textbox value based on dropdown list using Ajax and PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use //fuction to return the xml http object function getXMLHTTP() { var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCurrencyCode(strURL) { var req = getXMLHTTP(); if (req) { //function to be called when state is changed req.onreadystatechange = function() { //when state is completed i.e 4 if (req.readyState == 4) { // only if http status is "OK" if (req.status == 200) { document.getElementById('cur_code').value=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;"> <form style="text-align:center" method="post" action="" name="form1"> <p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p> <p>Quest : <select name="country" getCurrencyCode('find_ccode.php?country='+this.value)">' <?php mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query('select QuestID,QTitle, QDescrip from QuestList'); $options=""; while ($row=mysql_fetch_array($result)) { $QuestID=$row["QuestID"]; $QTitle=$row["QTitle"]; $options.="<OPTION VALUE=\"$QuestID\">".$QTitle; } $myFile = "test_catchoption.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $options); fclose($fh); ?> Choose your Quest <?=$options?> </SELECT> <br/><br/> Quest Description : <input type="text" name="cur_code" id="cur_code" ></p> </form> </body> </html> find_ccode.php <?php // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use $country=$_REQUEST['country']; $myFile = "testFilefindcc.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $country); fclose($fh); switch($country) { case "1" : mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query("select * from QuestList where QuestID = '1'"); $row = mysql_fetch_assoc($result); echo $row['QDescrip']; break; case "2" : echo "GBP"; break; case "3" : echo "NPR"; break; } ?> I am having a lot of trouble with this code, and I have no clue how to fix it. Right now, I have a GUI for a fictitious car dealership that has 5 populated drop down menus called Make, Model, Year, Color, and Mileage. What I want the code to do is read the selections made by the user with the drop down menus once the user hits the submit button and then filter the tables that I have in a mysql database to meets the choice requirements of the user. The code will bring up the GUI, but once I hit the submit button, I get the following errors Please if anyone can help me that would be fantastic. I really have no clue Hi there. Im a noob to sql and php not sure if this is right place to post, Im trying to get a dynamic drop down menu to show the 1st column in my sql database the column is called cat and holds category info ie audio, internet, music ect. ( i have no idea how to do lol ) it has taken me 2 days to find and edit this the bold and underline'd bit is what im trying to change with the dropdown menu. Or thinking bout it is there a way to do it with the URL. IE.. page name.php?cat=audio ? would that be easer ? is there any security issues with doing it that way ? Code================================== $db_host = '*******'; $db_user = '******'; $db_pwd = '*****; $database = 'nbbcj_co_uk'; $table = 'penapps'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT * FROM {$table} WHERE `cat` = 'audio' LIMIT 10 "); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); //echo "<h1>Table: {$table}</h1>"; echo "<table border='1' width='100%'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); //echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> code end ====================== the test page can been seen here http://www.nbbcj.co.uk/testd/1/test1.php Any more questions let me know Thanks for any help you can give, a we all have to start some ware lol thanks kaine. Hey all, This question is coming forth of another topic, but since that topic is not really about this issue, I posted this new topic. Okay, so I made a table, and each row is generated with a WHILE loop. In this while loop, there's also a form generated for each row/record, for updating them seperately. I'm having trouble with naming those forms to process them seperately. I could name them like name="form20110001", with the number being the record's id. But since there can be gaps between id's, how can I retreive them efficiently? And I want them to process all on a single process page, obviously. How can I do this easily? Can someone give me a concise example? Would appreciate it a lot. Thanks Hello Friends!.... here is the big idea. I am trying to make a form in which there will be 2 drop down lists which will be populating directly from MySQL DB .... Actually i am developing a student management system as my first PHP project... here i want to have 2 drop down lists first is roll number and second is student name. i want that when some one select the roll number in the first drop down the student name against it is automatically populated in the next drop down. please help me friends i am new to php and dont know soo much.! any help PLZZZZZZZZZZ Hi I have tried the mysql forum but have had no joy with an answer to my problem so wondered if php would be better. I want my users to be able to select from 5 different drop down lists where they can chose any combination from 1 up to all 5, I have attached the front end. These lists are being populated from mysql tables. Code for the drop down lists is as follows Code: [Select] <form action="horse-events-devon.php?url_countyid=<?php echo urlencode ($url_countyid ['url_countyid']) ; ?>&go" method="POST"> <table id="searchtable"> <tr> <th>Find By Discipline</th> <th>Find By Venue</th> <th>Find By Championship</th> <th>Find By Organiser</th> <th>Equine Association</th> <th>Submit Your Selections</th> </tr> <tr> <td><select name="dis_id"> <?php $upcomingdis = upcomingdis($url_countyid); $upcoming_dis_bycounty = mysql_fetch_assoc ($upcomingdis); ?> <?php do { ?> <option value="<?php echo $upcoming_dis_bycounty ['dis_id']; ?>" > <?php echo $upcoming_dis_bycounty ['dis_description']; ?></option> <?php } while ($upcoming_dis_bycounty = mysql_fetch_assoc ($upcomingdis)); ?></select></td> <td><select name="ven_id"> <?php $upvenbycounty_set = upcoming_venevents_bycounty($url_countyid); $upcoming_ven_bycounty = mysql_fetch_assoc ($upvenbycounty_set); ?> <?php do { ?> <option value="<?php echo $upcoming_ven_bycounty ['ven_id']; ?>" > <?php echo $upcoming_ven_bycounty ['ven_name']; ?></option> <?php } while ($upcoming_ven_bycounty = mysql_fetch_assoc ($upvenbycounty_set)); ?></select></td> <td><select name="champ_id"> <?php $championship_set = findchampionships(); $champlist = mysql_fetch_assoc ($championship_set); ?> <?php do { ?> <option value="<?php echo $champlist ['champ_id']; ?>" > <?php echo $champlist ['champ_description']; ?></option> <?php } while ($champlist = mysql_fetch_assoc ($championship_set)); ?></select></td> <td> <select name="org_id"> <?php $uporgbycounty_set = upcoming_organevents_bycounty($url_countyid); $upcoming_org_bycounty = mysql_fetch_assoc ($uporgbycounty_set); ?> <?php do { ?> <option value="<?php echo $upcoming_org_bycounty ['org_id']; ?>" ><?php echo $upcoming_org_bycounty ['org_name']; ?></option> <?php } while ($upcoming_org_bycounty = mysql_fetch_assoc ($uporgbycounty_set)); ?></select> </td> <td><select name="ass_id"> <?php $upassbycounty_set = upcoming_assevents_bycounty($url_countyid); $upcoming_assbycounty = mysql_fetch_assoc ($upassbycounty_set); ?> <?php do { ?> <option value="<?php echo $upcoming_assbycounty ['ass_id']; ?>" > <?php echo $upcoming_assbycounty ['ass_description']; ?></option> <?php } while ($upcoming_assbycounty = mysql_fetch_assoc ($upassbycounty_set)); ?></select></td> <td><input name="submit" type="submit" /><input name="countyid" type="hidden" value="<?php echo $url_countyid ['url_countyid']; ?>" /></td> </tr> </table> </form> My search processing is as follows Code: [Select] <?php if (isset($_POST['submit'])){ if (isset($_GET['go'])){ $countyid = $_POST['countyid']; $ven_id = $_POST['ven_id']; $dis_id = $_POST['dis_id']; $champ_id = $_POST['champ_id']; $org_id = $_POST['org_id']; $event_id = $row['event_id']; $sql = "SELECT DATE_FORMAT (events.startdate, '%a, %d, %b') AS stdate, events.event_id, events.title, events.ven_id, events.org_id, venue.county_id, venue.ven_id, eventdisciplines.event_id, eventdisciplines.dis_id, county.county_id, discipline.dis_id \n" . "FROM events \n" . "LEFT OUTER JOIN eventdisciplines \n" . "ON events.event_id = eventdisciplines.event_id \n" . "LEFT OUTER JOIN discipline \n" . "ON eventdisciplines.dis_id = discipline.dis_id \n" . "LEFT OUTER JOIN venue \n" . "ON events.ven_id = venue.ven_id \n" . "LEFT OUTER JOIN county \n" . "ON venue.county_id = county.county_id \n" . "WHERE events.ven_id = ({$ven_id} OR events.org_id = {$org_id})\n" . "AND events.startdate > NOW()\n" . "AND venue.county_id = {$countyid} \n" . "ORDER BY startdate ASC"; $result = mysql_query ($sql, $connection); ?> How am I best to do this please? my OR within the mysql does not work, should I not be doing this with php in the search processing? someones help would really be appreciated, just to point me in the right direction. [attachment deleted by admin] |