PHP - Drop Down Box
Hi all, ive just coded a new thing for my website which lets users upgrade there car to a certain speed, its all coded and works fine, but im just not sure how todo one thing on it.
<?php $getall = mysql_query("SELECT car, id FROM garage WHERE owner='$username'"); while($row = mysql_fetch_array($getall)){ echo $row['car']. " - ". $row['id']; echo "<br />"; } ?> That bit of my code, select the car and the car ID from my table garage, but i'm wanting it in a drop down box which shows all the cars in there garage, but not sure how I would do this. Any advice? Thanks. Similar TutorialsI am creating a form that will allow the user to select the make of vehicle "FORD" for example. If that make of vehicle is selected among different makes of vehicles, then another box will appear, with all the models for that particular model "Fiesta" for example. What type of code accomplishes this setup in my web page? I do not want to list 500 models in one drop down list, but just those for each make in the first drop down list. Thanks much! Hi All, I have 2 tables: one CarMake - CarMakeID - CarMakeDesc two CarModel - CarModelID - CarModelMake - CarModelDesc Depending on what the user selects in the first dropdown (carmake) the possible selection in the second dropdown (model) needs to be limited to only the models from the selected carmake. in the second table (Carmodel : the 'CarModelMake' = CarMakeID, to identify the make) How do I limit the dropdown 'CarModel' based on the selected CarMake in the first dropdown. link : http://98.131.37.90/postCar.php code : -- -- -- Code: [Select] <label> <select name="carmake" id="CarMake" class="validate[required]" style="width: 200px;"> <option value="">Select CAR MAKE...</option> <?php while($obj_queryCarMake = mysql_fetch_object($result_queryCarMake)) { ?> <option value="<?php echo $obj_queryCarMake->CarMakeID;?>" <?php if($obj_queryCarMake->CarMakeID == $CarAdCarMake) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCarMake->CarMakeDesc;?></option> <?php } ?> </select> </label> <label> <select name="carmodel" id="CarModel" class="validate[required]" style="width: 200px;"> <option value="">Select MODEL...</option> <?php while($obj_queryCarModel = mysql_fetch_object($result_queryCarModel)) { ?> <option value="<?php echo $obj_queryCarModel->CarModelID;?>" <?php if($obj_queryCarModel->CarmodelID == $CarAdCarModel) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCarModel->CarModelDesc;?></option> <?php } ?> </select> </label> I'm a novice.. and appreciates all the help ! hi how do i get the id value from the dropdown selection from the database Here is my code. i need the id to store it another table to refer it in my application. its like a categories and subcategories table. <html> <form id="name" action="<?php $_POST['SERVER_SELF'] ?>" method="POST" > <input type="text" name="name1"> <br> <select name="select"> <?php mysql_connect('localhost','root','') or die('Could not connect to mysql ' . mysql_error()); // error message mysql_select_db("dbtest") or die(mysql_error()); $query = "select name,id from main"; $result = mysql_query($query); if ($query) { while ($row = mysql_fetch_array($result)) { $strB=$row['name']; ?> <option value="<?php $stra ?>"><?php echo $strB ?></option> <br> <?php } } ?> </select> <input type="text" name="name2"> <br> <input type="submit" name="submit1"> </form> <?php if(isset($_POST['submit'])) { //$name=$_POST['val']; $strB=$stra; mysql_connect('localhost','root','') or die('Could not connect to mysql ' . mysql_error()); // error message mysql_select_db("dbtest") or die(mysql_error()); $query = "insert into sub (sub) values('$strB')"; $result = mysql_query($query); if ($query) { echo "query executed"; } } ?> </html> thanks The code for the drop down: Code: [Select] echo '<select name="select" ONCHANGE="goto(this.form)">'; while ($dropDown > 0) { if ($page == $dropDown) { $selected = 'selected="selected"'; } else { $selected = ""; } echo "<option value=\"searchFlights.php?page=" . $dropDown . "\" $selected>" . $dropDown . "</option>"; $dropDown = $dropDown - 1; } echo '</select>'; It works fine, but I want 1 to be at the top of the list and go down from there because right now, it starts with the biggest number and goes down. Any suggestions? Thanks! Hello, I'm trying to use a dropdown to display different divs. <html> <head> <title>DDlist Div Display</title> <script type="text/javascript"> function ShowDivArea(info) { var sel = document.getElementById('divArea').getElementsByTagName('div'); for (var i=0; i<sel.length; i++) { sel.style.display = 'none'; } if (info == '0') { return; } document.getElementById('divArea'+info).style.display = 'block'; } </script> <style type="text/css"> .divArea { display:none; height:100px; width:200px; border:1px solid red; } </style> </head> <body> <select id="DDDivList" onchange="ShowDivArea(this.selectedIndex)"> <option value="0" selected> -- Select A Design Service --</option> <option value="1"> QR Bookmark </option> <option value="2"> Twitter </option> <option value="3"> Ning or Tumblr </option> <option value="4"> Flyers </option> <option value="5"> Business Card or Brochure</option> <option value="6"> Album or Mixtape cover</option> <option value="7"> Other</option> </select> <div id="divArea"> <div id="divArea1" class="divArea"> <h1>QR Bookmarks</h1> <form action='qrgen.php' method='POST'> <input type='text' name='bmarksite'> URL<br> <input type='text' name='sitedesc'> Description<br> <input type='submit' value='Convert'><br> <?php include("QrCodes.php") ?> <?php $bmarksite = $_POST['bmarksite']; $sitedesc = $_POST['sitedesc']; if ($sitedesc&&$bmarksite) { $qrcode = new QrCodes; $qrcode -> IsImage =1; echo $qrcode -> GetBookmark("$bmarksite","$sitedesc"); echo "</br>"; echo $bmarksite; echo "</br>"; print $sitedesc; } else { echo "Please fill in all the required fields."; } ?> </div> <div id="divArea2" class="divArea">Twitter</div> <div id="divArea3" class="divArea">Ning or Tumblr</div> <div id="divArea4" class="divArea">Flyers</div> <div id="divArea5" class="divArea">Business Card or Brochure</div> <div id="divArea6" class="divArea">Album or Mixtape Cover</div> <div id="divArea7" class="divArea">Other</div> </div> </body> </html> The problem is with this line: <form action='qrgen.php' method='POST'>. I am using a wordpress page template. What should I change the qrgen.php to? Or how do I get it to work? Thank you for your help. trying to get my drop down box to display more then one result. I have two users with Mod wrote in the column Monitor but right now it only displays just the one. So I need to display all the goaulds that have mod in the monitor column <?php Code: [Select] $result = mysql_query("SELECT goauld FROM users WHERE monitor ='mod' ORDER BY id DESC") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if($row['goauld'] == $_POST['name_list']){ echo '<div class="containerc">'; echo '<div class="search">'; echo '<form method="post" >'; echo '<select name="name_list" class="textbox" id="name_list">'; echo "<option value=\"".$row['goauld']."\">".$row['goauld']."</option>"; echo "<option selected=\"selected\" value=\"".$row['goauld']."\">".$row['goauld']."</option>"; echo '</select>'; echo '<input type="submit" name="remove" id="remove" value="Remove">'; } } } '</form>'; '</div>'; '</div>'; ?> Hello, must admit i'm very new to this and just a hobiest , I am creating a page which will be used for logging information. With a mysql database i have two tables "tbl_rides" & "tbl_courses" rides is the main table for storing information and has a foreign key associating column "course_id" with course_id in the tbl_courses What i want to do on a HTML/PHP page is display a drop down box that has the contents of "course" from the tbl_courses but when the user selects it and submits the record is written to the main form "tbl_rides" "course_id" so display the friendly name via the foreign key but the record is written to "tbl_rides" Can that be done .. am i going about this wrong ?
Thanks for any help Andrew. Hi all, ive got a script ive finishing coding from the other day, but ive got a slight problem with it. <?php if ($fetch->missions == "4"){ // Mission 4, Toyota Aygo up to 500MPH $car = "Toyota Aygo"; if ($garage->car == $car && $garage->mph == "500"){ $rightcar = "Yes"; }else{ $rightcar = "No"; } if (strip_tags($_POST['submit'])){ if ($rightcar == "Yes"){ echo ("<table width='30%' cellpadding='0' align='center' cellspacing='0' border='1' class='table'> <tr> <td class='header' align='center'>Well Done!</td> </tr> <tr> <td>You Successfully Completed Mission 3!</td> </tr> </table><br />"); $newmoney = $fetch->money + 70000000; $newrep = $fetch->rep + 750000; mysql_query ("UPDATE users SET money='$newmoney' WHERE username='$username'"); mysql_query ("UPDATE users SET rep='$newrep' WHERE username='$username'"); mysql_query ("UPDATE users SET missions='5' WHERE username='$username'") or die ("Error - Query : Line 121 : " . mysql_error()); mysql_query ("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` , `saved` , `event_id` ) VALUES ( '', '$username', 'System', 'Well done! <br /> As You completed Mission 4 Successfully we will reward you with<br /> £70,000,000 Money<br /> 750,000 Rep!', '$date', '0', '0', '0' )"); } } } // Mission 4 ?> <?php if ($fetch->missions == "4"){ ?> <form action="" method="POST" name="mission4"> <table width="50%" cellpadding="0" cellspacing="0" border="1" class="table" align="center"> <tr> <td class='header' align='center'>Mission 4</td> </tr> <tr> <td>Now SD Stars can now see your progressing, they have asked you if you can get a Toyota Aygo up to 500MPH. You must get it to them without any damage to prove your werthy!</td> </tr> <tr> <td align='center' class='header'>Select Your Car:</td> </tr> <tr> <td><select class="dropbox"> <option selected>Pick Car</option> <?php $get=mysql_query("SELECT * FROM garage WHERE owner='$username' AND car='Toyota Aygo' AND mph='500'"); while($stats=mysql_fetch_object($get)){ echo "<option value=?carname=$stats->id>$stats->car, $stats->damage%, $stats->mph MPH</option>"; } ?></select></td> </tr> <tr> <td class='omg'><input type="submit" name="submit" class="button" value="Send Car!"></td> </tr> </table> </form> <?php } ?> I blive it works apart from the Drop Down Box. It selects all the cars its suppose to but when I pick the car and press submit it just basicly refreshes the page :S. I'm not sure why its doing it . Can any one else see the problem? Thanks for any help given 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. im fairly new to php so tend to do trial and error..... more error than trial tbh. im wondering if it is possible to get a drop down menu to fill from a mysql database and to arrange it alphabetically. i have created the menu just dont know how to arrange it better. also how can i use the items id in drop menu to load other info from that row on the database. hope you can help me. Code: [Select] <FORM> <?php $result = mysql_query( "SELECT * FROM movie_info" ) ; echo "<select name= film onChange='submit()' >film name</option>"; while ($nt=mysql_fetch_array($result)){ ?> <?php echo "<option value='$nt[id]'>$nt[title] </option>"; } ?> </select> </FORM> Hello there, i have a pretty simple problem, but i cant seem to get over it hence this post. I have a very simple form with 2 text boxes and a dropdown box. The user is supposed to insert an actor to the database using that form, but the thing is that i can't get the value from my dropdown box for some reason. Anyway here's the form. Code: [Select] <div id="content"> <?php if (isset($_POST["actorID"]) && isset($_POST["actorName"]) && isset($_POST["nation"])) { if ($_POST["actorID"] != "" && $_POST["actorName"] != "") { $link = mysql_connect('localhost', 'Ugluth', 'dracul'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("videoclub", $link); $sql="INSERT INTO actors (Actor_ID, Actor_Name, Actor_Nation) VALUES ('$_POST[actorID]','$_POST[actorName]','$_POST[nation]')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; mysql_close($link); } } else { echo "All fields need to be completed to add the record."; } } $link = mysql_connect('localhost', 'turu', 'tururu'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("videoclub", $link); $result_nation = mysql_query("SELECT * FROM nationalities"); $row = mysql_fetch_array($result_nation); mysql_close($link); ?> <form action="actor_add.php" method="post"> <table> <tr> <td> Actor ID: </td> <td> <input type="text" name="actorID"> </td> </tr> <tr> <td> Actor Name: </td> <td> <input type="text" name="actorName"> </td> </tr> <tr> <td> Actor Nationality ID: <?php ?> </td> <td> <select name="nation"> <?php while($row = mysql_fetch_array($result_nation)) { ?> <option value="<?php $row[0]; ?>"><?php echo $row[1]; ?></option> <?php } ?> </select> </td> </tr> </table> <?php mysql_free_result($result_nation); ?> <input type="submit" value="Submit" /> </form> </div> <!-- end #content --> I'm trying to enter the value to my query using '$_POST[nation]' on the $sql string i use for query. I have also tried just displaying it on the screen to see what value it holds, but it just wont show anything. Also i don't really need this answered for this particular problem, but in general its good to know, how can i select the value from the text of each option on the drop down box? The $row[0] holds the id while $row[1] holds the name. Thank you in advance and if u need any more information just let me know 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! Hi all Im looking to do a "SIMPLE" search on a databse usign php. I want to have a drop down box like so : <select name="Lowest"> <option>0</option> <option>100</option> <option>200</option> </select> this is for the prices i want 2 of these so that the first will be the lowest price and the second will be the higher price Then i will make a query to SELECT * WHERE ( i dont know how to call the results from the select box here to display the whole tabled results ) any help please thnax Okay, so, here's the scenario. I have a form that is editing an item that is already in the database. The text fields fill in just fine with that info. However, the drop down menus don't retrieve that info, rather resorting to the defaults, which can be a problem if you don't remember what you originally had. Is there anyway to make the dropdown menus pull the info from the table and use that rather than resorting back to the default? I tried using this: Code: [Select] <tr><td width="20%">Bonus:</td><td><select name="bonus" value="{{bonus}}"> <option value="Attack" {{bonus1select}}>Add to the attack power of weapon</option> <option value="Defense" {{bonus2select}}>Add to the defensive power of armor</option> <option value="None" {{bonus3select}}>No effect</option> </select><br /></td></tr> So, it's obvious the "value" portion not working. Any help would be great!! I have a "select"-drop down bar and I want to have a numbered list in it, i've tried but it doesn't seem to be possible. Is there any way that i'm able to do this? I have a like 100 of these in a drop down box and drop down box on html is really new to me Id like to put all the option values into one variable. but i dont know if the form works like that? cause I want to store the -1200 and not whats in the drop down box I feel like my approach with this is way off if someone could help guide me in a direction would appreciate it so I can say Code: [Select] <?php mysql_query("UPDATE users SET time_offset= '".mysql_real_escape_string($_POST['$________'])."' WHERE id = '".mysql_real_escape_string($_SESSION['user_id'])."'"); <select name="cars"> <option value="-1200">(GMT -1200) International Date Line West </option> <option value="-1100">(GMT -1100) Coordinated Universal Time -11 </option> <option value="-1100">(GMT -1100) Samoa </option> <option value="-1000">(GMT -1000) Hawaii </option> <option value="-0900">(GMT -0900) Alaska </option> ?> Hi. I have drop down boxes for date and time that work. The year is a problem because I am using variables instead of fixed values. Code: [Select] <select name="Year" style="width:60px"> <option value="2010" >Test <option value="<?=$ThisYear?>" <? if ($Year == "<?=$ThisYear?>"){?> SELECTED <?}?> ><?=$ThisYear?> <option value="<?=$NextYear?>" <? if ($Year == "<?=$NextYear?>"){?> SELECTED <?}?> ><?=$NextYear?> </select> <select name="Hour" style="width:50px"> <option value="10" <? if ($_SESSION["Hour"] == "10"){?> SELECTED <?}?> >10 <option value="11" <? if ($_SESSION["Hour"] == "11"){?> SELECTED <?}?> >11 <option value="12" <? if ($_SESSION["Hour"] == "12"){?> SELECTED <?}?> >12 <option value="13" <? if ($_SESSION["Hour"] == "13"){?> SELECTED <?}?> >13 <option value="14" <? if ($_SESSION["Hour"] == "14"){?> SELECTED <?}?> >14 <option value="15" <? if ($_SESSION["Hour"] == "15"){?> SELECTED <?}?> >15 <option value="16" <? if ($_SESSION["Hour"] == "16"){?> SELECTED <?}?> >16 <option value="17" <? if ($_SESSION["Hour"] == "17"){?> SELECTED <?}?> >17 <option value="18" <? if ($_SESSION["Hour"] == "18"){?> SELECTED <?}?> >18 <option value="19" <? if ($_SESSION["Hour"] == "19"){?> SELECTED <?}?> >19 <option value="20" <? if ($_SESSION["Hour"] == "20"){?> SELECTED <?}?> >20 </select> however this works Code: [Select] <select name="Year" style="width:60px"> <option value="2010" >Test <option value="<?=$ThisYear?>" <? if ($Year == "2011"){?> SELECTED <?}?> ><?=$ThisYear?> <option value="<?=$NextYear?>" <? if ($Year == "2012"){?> SELECTED <?}?> ><?=$NextYear?> </select> Can anyone help with this please TIA Desmond. helo i a newbie in php. i need some help regarding my system. i want my data from database to display in drop down menu form.anyone have idea how to do that? i really need some help. i have search all over and couldn't find any solution. any suggestions would be helpful Hi, i know this is probably very basic but i have been banging my head and looking for tuts. i have built a mysql php dropdown menu. all displays fine. now, how do i get the menu to actualy take me to a new url? the new url should be www.mysite.com/"menu selection" Code: [Select] <? include_once 'includes/db.php'; $result = mysql_query("select * from crimerate WHERE DISTRICT = 'Limpopo'", $con); if (!$result) { die('Invalid query: ' . mysql_error()); } $options=""; while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $crime=$row["CRIME"]; $options.="<OPTION VALUE=\"$id\">$crime</option>"; } ?> <SELECT NAME=crime> <OPTION VALUE=0>Choose <?=$options?> </SELECT> |