PHP - Drop Down List Default For Editing
Okay, so, here's my dilemma. I'm wanting to have it so someone can edit an item in the database, but it is a dropdown menu for the options to choose from.
How do I make it so that the option that the item currently is is what the default showing is? For instance, if the item is for a "warrior", it will show warrior already in the dropdown menu. However, I could go to the dropdown menu and select a different option if I wanted. The {{class}} doesn't seem to give that default. Right now, it just defaults to "All" regardless of what the item truly goes to, such as "warrior". Thanks in advance!! Here's what I have for the coding: <tr><td width="20%">Class:</td><td><select name="class" value="{{class}}"> <option value="1" {{class1select}}>All</option> <option value="2" {{class2select}}>Alchemist</option> <option value="3" {{class3select}}>Assassin</option> <option value="4" {{class4select}}>Dark Arts</option> <option value="5" {{class5select}}>Dark Paladin</option> <option value="6" {{class6select}}>Entertainer</option> <option value="7" {{class7select}}>Hunter</option> <option value="8" {{class8select}}>Mage</option> <option value="9" {{class9select}}>Monk</option> <option value="10" {{class10select}}>Paladin</option> <option value="11" {{class11select}}>Pirate</option> <option value="12" {{class12select}}>Priest</option> <option value="13" {{class13select}}>Psion</option> <option value="14" {{class14select}}>Scholar</option> <option value="15" {{class15select}}>Thief</option> <option value="16" {{class16select}}>Warlock</option> <option value="17" {{class17select}}>Warrior</option> </select></td></tr> Similar TutorialsI am working on a project that uses a drop down list to chose the category when inserting new data into the database. What I want to do now is make the drop down list default to the chosen category on the list records page and the update page. I have read several tutorials, but they all say that I have to list the options and then select the default. But since it is possible to add and remove categories, this approch won't work. I need the code to chose the correct category on the fly. There are two tables, one that has the category ID and category name. The second table has the data and the catid which is referenced to the category id in the first table. Code: [Select] -- -- Table structure for table `categories` -- DROP TABLE IF EXISTS `categories`; CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `categories` varchar(37) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=40 ; -- -------------------------------------------------------- -- -- Table structure for table `links` -- DROP TABLE IF EXISTS `links`; CREATE TABLE IF NOT EXISTS `links` ( `id` int(4) NOT NULL AUTO_INCREMENT, `catid` int(11) DEFAULT NULL, `name` varchar(255) NOT NULL DEFAULT '', `url` varchar(255) NOT NULL DEFAULT '', `content` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`), KEY `catid` (`catid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ; Then is the list records file, I have Code: [Select] <?php include ("db.php"); include ("menu.php"); $result = mysql_query("SELECT categories FROM categories") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $categories=$row["categories"]; $options.= '<option value="'.$row['categories'].'">'.$row['categories'].'</option>'; }; $id = $_GET['id']; $query="SELECT * FROM links ORDER BY catid ASC"; $result=mysql_query($query); ?> <table width="65%" align="center" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="100%" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="7"><strong>List data from mysql </strong> </td> </tr> <tr> <td align="center"><strong>Category ID</strong></td> <td align="center"><strong>Category ID</strong></td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>URL</strong></td> <td align="center"><strong>Content</strong></td> <td align="center"><strong>Update</strong></td> <td align="center"><strong>Delete</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td> <SELECT NAME=catid> <OPTION>Categories</OPTION> <?php echo $options; ?> </SELECT> </td> <td><? echo $rows['catid']; ?></td> <td><? echo $rows['name']; ?></td> <td><a href="<? echo $rows['url']; ?>"><? echo $rows['url']; ?></a></td> <td><? echo $rows['content']; ?></td> <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td> <td align="center"><a href="delete.php?id=<? echo $rows['id']; ?>">delete</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> So, how do I get this code Code: [Select] $result = mysql_query("SELECT categories FROM categories") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $categories=$row["categories"]; $options.= '<option value="'.$row['categories'].'">'.$row['categories'].'</option>'; }; <SELECT NAME=catid> <OPTION>Categories</OPTION> <?php echo $options; ?> </SELECT> to give me an output that will be something like if catid exactly matches categories.id echo categories.categorie ??? so far everything I have done produces either a default category of the last category, the catid (which is a number), all of the categories (logical since catid will always be = id, or nothing. How do I get just the category name? I will keep reading and try to figure this out, but any help would be greatly appreciated. Thanks in advance 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. having a problem figuring out how to change the default on a drop down box to equal the users current timezone. So when they view it the drop box default is showing what their setting is atm. The problem is the value is differant from whats displayed. Is it possible to some how say if users time offset is equal to a option value set selected=""> to yes. if not what is the idea behind this? Cant find a guide showing an example In other drop down boxes where the value is the same as whats displayed I just simply created another value field at the top of the list and echo it in. Code: [Select] <select name="gmt"> <option value="-28800">(GMT -0800) Pacific Time </option> <option value="-25200">(GMT -0700) Mountain Time </option> <option value="-21600">(GMT -0600) Central Time</option> <option value="-18000">(GMT -0500) Eastern Time </option> </select> Hi All, I've a loop which lists a series of options as checkboxes. What I'd like to do is set 1 as a default. But I've no idea how to do it!? Here's the code: <?php $i = 0; ?> <?php if ( bp_has_groups() ) : while ( bp_groups() ) : bp_the_group(); ?> <input type="checkbox" id="field_reg_groups_<?php echo $i; ?>" name="field_reg_groups[]" value="<?php bp_group_id(); ?>" /><?php bp_group_name(); ?> <?php } ?> <?php $i++; ?> Any help is much appreciated TIA I have a simple form that edits student information. I have several fields that I have a drop down list pulled as an array from a separate table. I would like the information that is already entered on the student to be the default but still have the drop down list available if the item was entered in error. For example: Drop down list of all the states of America, OH was entered for the student, when the edit form comes up for State in Address I would like OH to be the default but still have the list to choose if OH was entered in error. I have tried selected = $selected but then the entire drop down changed to OH. I am very, very much a beginner in this <?php // list of possible modules comes from database $state_array=get_states(); //display as a drop down list for end user to choose if (!is_array($state_array)) { echo "<p>No States are currently available<p>"; return; } foreach ($state_array as $row) { echo "<option value=\"".($row['stateid'])."\""; // if existing state, put in current catgory echo "<strong> ".($row['stateid'])."</strong><br />"; echo "<option select=\"selected\">OH"; } ?> So i have this CMS that is used by lots of users and generally they do have rights to edit each others article. So now i'm thinking how can i at least warn them that somebody else is already editing it. Just that. maybe with sessions? but what happens when a user just closes the windows, will it destroy it. i taught about storing the value to mySQL but again what if the user closes the windows and so on. i never did this and i could use a boost. thanks guys Hi ,
I am pretty new to php. I would like to create a php website based on folders.
I have a code so far that shows the names of folder in a selection box. What I would like to achieve now is how i get the images inside the folder after I click on submit. I know how to get the images with a glob function. What I don't know is how to get the value of each specific folder name. How would I do that?
I have this code so far to get the names of the folders in the selection box:
<form action="test.php" method="post"> <select name="myDirs"> <option value="" selected="selected">Select a genre</option> <?php $dirs = glob("*", GLOB_ONLYDIR); foreach($dirs as $val){ echo '<option value="'.$val.'">'.$val."</option>\n"; } ?> </select> <input type="submit" name="submit2"> <?phpif (isset($_POST['submit2'])) Helllo Every1 well im kinda new to php and i needed some help i was working on a page all my text boxes and check boxes are at the bottom of my file and like this //====================================================================== </script> </head> <body> <div style="margin-left: 170px"> <input type="checkbox" id="getitems" checked value="1">Run Plugin? <input type="checkbox" id="sellitm" checked value="1">Sell Items?<br><br> Item Name:<br><input type="text" id="itemd" value=""><br><br>How Many Cycles?:<br><input type="text" id="runtm" value="10"></div> <div style="margin-left: 170px"><br> <button id="btn_save" style="color:white;background-color:#00660F;border-width:1px;border-style:solid; "> Save settings </button> </div> '; echo $this->ObjectTable(); echo ' </body> </html> '; } } ?> and well i decided to do away wit one of the text boxes and use a drop down list instead that is populate from a text file and the only code that i could find that i was able to get working was this 1 <?php $text = file_get_contents("itemlist.txt"); $array = explode("\n",$text); echo "<select>"; foreach ($array as $value) { echo "<option value='$value'>$value</option>"; } echo "</select>"; and the problem im having is with that one it just stays at the top of the page when loaded like i have no way to position it... and im really stuck i tried saving it in another php and i tried using <?php include(); ?> function but it did not work if any1 could help me out that would be awsome. T.I.A 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? hi, I'm sruggling to get a drop down list to post the chosen value from an sql database.. could someone please point me in the right direction many thanks! Hello, I'm trying to get a drop down list (ordinary html function, select option ...) but I want it to start from an image. When you click the image I want the drop down list to appear. Hove can I do this? /Pelle Hey guys, I made in php an sql droplist. But I need some help. I want it to work like this. When I select something from the list and click Add To Cart, that also the product gets send to the cart and not only the quantity. you can check it out here : http://fhcs.be/cart-demo2/index.php I also added my index.php as an attachment Greets I'm useing a simple HTML drop-down list box. But now I want to be able to and an editable drop-down box so that if the particular item in the drop-down is not changed it won't update the database. But if a new value is selected it will update the DB with the new value.
I am not clear on a couple of things. should the valuse of the drop down be in a seperate DB table. And then the script to change the new value or keep the old.
I've googled this and can't seem to find a workable solution.
Thanks in advance,
Basically I have a form and What I want it to do is when a user selects the 'For Sale' radio button the minimum and maximum prices will be displayed in the drop down list as "70,000"+ but when the user selects the 'To Rent' radial button then the minimum and maximum drop down list prices will change to e.g. "200"+. How would I do this? Heres my Code for the form: Code: [Select] <div id="ptype"> <input type="radio" class="styled" name="ptype" value="forsale"/> For Sale <p class="increase"> <input type="radio" class="styled" name="ptype" value="forrent"/> To Rent </p> <p class="increase"> <input type="radio" class="styled" name="ptype" value="any"/> Any </p> </div> </td> </tr> </table> <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <select name="min bedrooms"> <?php $roomLimit = 5; for($minRooms = 0; $minRooms <= $roomLimit; $minRooms++){ if ($minRooms == 0){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value=\"$minRooms\">$minRooms</option>"; } } ?> </select> to <select name="max bedrooms"> <?php $roomLimit = 5; for($maxRooms = 0; $maxRooms <= $roomLimit; $maxRooms++){ if ($maxRooms == 0){ echo"<option value=\"0\" selected=\"selected\">No Max</option>"; } else{ echo "<option value=\"$maxRooms\">$maxRooms</option>"; } } ?> </select> </div> </td> <td><p class="PR">Price range:</p></td> <td><div id="PR"> <select name="min price" style='width:80px;'> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice =( $minPrice+ 10)){ if ($minPrice == 40){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value=\"$minPrice000\">£$minPrice,000</option>"; } } ?> </select> to <select name="max price" style='width:80px;'> <?php $priceLimit = 350; for($maxPrice = 40; $maxPrice <= $priceLimit; $maxPrice =( $maxPrice+ 10)){ if ($maxPrice == 40){ echo"<option value=\"0\" selected=\"selected\">No Max</option>"; } else{ echo "<option value=\"$maxPrice000\">£$maxPrice,000</option>"; } } ?> </select> Thanks in advance. I'm doing this activity where a user chooses a base timezone and when the user clicks convert the current time in the selected GMT will be converted to GMT-11 to GMT+13. As of now, I have these codes: act09_view.php: Code: [Select] <?php session_start(); $s="GMT "; echo "Select the base time zone:</br>"; for($n=-11;$n<=13;$n++) { if ($n>=0) $s="GMT +"; $gmt[]=$s . $n . "</br>"; } echo "<select name='gmt'>"; foreach ($gmt as $value) { echo '<option value="' . $value . '">' . $value . '</option>\n'; } echo '</select>'; //$_SESSION['value']=$value; ?> <form action="act09_process.php"> </br><input type='submit' value='Convert'/> </form> act09_process.php: Code: [Select] <?php session_start(); //$value=$_SESSION['value']; //echo $value; date_default_timezone_set('Asia/Manila'); $gmttime=date('M j, Y g:i:s A'); echo "The current date and time at" . " is " . $gmttime; ?> I've tried using session variables. I think I executed them incorrectly. The output is supposed to look like this: I have a drop down list which retrieves site name acronym and the url from the database. I need help in 2 things. 1.I do not want the url to be displayed in the drop down list. 2. When I hit submit I need to echo the sitename acronym as well as the url in a page called display.php. Here is my code so far: Code: [Select] <form action="display.php" method ="post"> <tr> <td>Category</td> <td> <select name="new_id"> <option value="">=============</option> <?php foreach($acronym as $key=>$value){ ?> <option value="<?php echo $value['site_id']; ?>"><?php echo $value['acronym']; ?></option> <option value="<?php echo $value['site_id']; ?>"><?php echo $value['url']; ?></option> <?php }?> </td> </tr> <input type="submit" name="submit" value="submit" /> </form> I have two basic dropdown lists in a form, my question is this: After selecting an item from the 1st dropdown list, the second dropdown list should automatically load only fields that are connected with the first selected item. (ex Site1 has Tank01 and Tank06, but Site2 has Tank03, Tank04 and also a Tank06). What is the script needed / or how do I change my script to accommodate this? Here is the basic script I use for the second dropdown list: <?php include("../xxx.php"); $cxn = mysqli_connect($host,$user,$password,$dbname); $query = "SELECT DISTINCT `diesel_tank_id` FROM `diesel_tank` ORDER BY `diesel_tank_id`"; $result = mysqli_query($cxn,$query); while($row = mysqli_fetch_assoc($result)) { extract($row); echo "<option value='$diesel_tank_id'>$diesel_tank_id</option>\n"; } ?> Hello all,
I am new in php and would like to help me in in code.
I would like to implement a html form that will upload to my linux server some files, some info as well and will run a bash command.
To be more clear, users will:
Send to the linux server two files (I have done it).
Select from a drop down list a specific directory, and once this specific directory has been selected to activate one other drop down menu with its childs.
Send all those info to a bash script.
For case b, assume that we have the following structure
my_dir/cars/brand1
my_dir/cars/brand2
my_dir/cars/brand3
my_dir/motors/brand5
my_dir/motors/brand6
the first drop down list should list only cars and motors while the second only brand1, brand2, and brand3 if cars is selected or brand5 and brand6 if motors is selected.
For case c, once the form is submitted, I would like the command:
./script.sh –a uploadedfile1 –b uploadedfile2 –c dropdown1 –d dropdpwn2
Any help is appreciated.
Best,
how do i loop this so that the option in the drop down list loop. i tried this but get an error Code: [Select] <select name="age"><?php for ($i=10; $i<71; $i++;) { echo "<option value='$i'>$i</option>"; } ?></select> I have a drop down list that contains expiration dates in the format 01/12 and if the user selected a certain drop down list I would like that same date selected. Does anyone know the code to do this? Thanks. |