PHP - Options Not Loading Inside Of Select Dropdown
I'm trying to figure out why the options aren't appearing inside the select dropdown. Any ideas why?
Code: [Select] echo "<label for=" . $row2['fullName'] . ">" . $row2['fullName'] . "</label>"; echo "<select name=" . $row2['fullName'] . " id=" . $row2['fullName'] . " class=dropdown title=" . $row2['fullName'] . " />"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } } echo "</select>"; } Similar TutorialsHey Guys, Here is my issue. I have a MySQL database with a table of products. I use this table to generate a mutliselect form element that is used int a larger form. The larger form contains other information relevant to an issue that we are having with that product (such as an outage). Anyway, the form works fine and the form validation works fine and I write it to the database fine. The issue I'm having is how to save the mutliselect options most efficiently. This is my current process: 1. User creates a new entry from the form and clicks save 2. The form is validated 3. All entries are written to the database in a table called "incidents" (content inclues, timestamps, description of the problem, the impact, who to contact, etc) 4. Because the products list can vary from 1 product to all (~30) products I broke it out into a separate table called "impacted_products". I then loop through each of the selected products and write one row for each product using the id from the row in the "incidents" table to define the tables relationship. Example of DB results: "incidents" +-----------------+------+----------+---------------------+---------+---------+ | notification_id | what | impact | time_start | summary | contact | +-----------------+------+----------+---------------------+---------+---------+ | 235235 | Test | None.... | 2011-02-08 13:41:00 | Test | 3 | +-----------------+------+----------+---------------------+---------+---------+ "impacted_products" +-----+-----------------+------------+---------------------+---------+ | id | notification_id | product_id | timestamp | deleted | +-----+-----------------+------------+---------------------+---------+ | 202 | 235235 | 7 | 2011-02-10 14:30:42 | 0 | | 203 | 235235 | 37 | 2011-02-10 14:30:42 | 0 | | 204 | 235235 | 23 | 2011-02-10 14:30:42 | 0 | +-----+-----------------+------------+---------------------+---------+ 5. Now the users wants to go back and make some updates. 6. They click the edit button from the menu on screen and the form is brought back up and all options/fields are filled out from that which is stored in the database. 7. They make their edits and save again. 8. Now this time it simple updates the "incidents" table but for the products table I do a: "UPDATE impacted_products SET deleted=1 WHERE notification_id='$ID'" and "delete" all the old impacted_products for this particular incident and then loop through all the products that the user still had selected and write them to the database again. 9. And repeat So as you can see this could end up with a lot of "useless" entries in the database since my scripts only pay attention to those "impacted_products" whose deleted value is set to 0. Example: +-----+-----------------+------------+---------------------+---------+ | id | notification_id | product_id | timestamp | deleted | +-----+-----------------+------------+---------------------+---------+ | 176 | 235235 | 37 | 2011-02-08 15:26:25 | 1 | | 177 | 235235 | 43 | 2011-02-08 15:26:25 | 1 | | 178 | 235235 | 37 | 2011-02-08 15:37:58 | 1 | | 179 | 235235 | 43 | 2011-02-08 15:37:58 | 1 | | 180 | 235235 | 1 | 2011-02-08 15:39:49 | 1 | | 181 | 235235 | 7 | 2011-02-08 15:39:49 | 1 | | 182 | 235235 | 37 | 2011-02-08 15:39:49 | 1 | | 183 | 235235 | 43 | 2011-02-08 15:39:49 | 1 | | 184 | 235235 | 1 | 2011-02-08 15:40:53 | 1 | | 185 | 235235 | 7 | 2011-02-08 15:40:53 | 1 | | 186 | 235235 | 37 | 2011-02-08 15:40:53 | 1 | | 187 | 235235 | 43 | 2011-02-08 15:40:53 | 1 | | 188 | 235235 | 37 | 2011-02-10 10:00:47 | 1 | | 189 | 235235 | 1 | 2011-02-10 12:17:05 | 1 | | 190 | 235235 | 7 | 2011-02-10 12:17:05 | 1 | | 191 | 235235 | 13 | 2011-02-10 12:17:05 | 1 | | 192 | 235235 | 37 | 2011-02-10 12:17:05 | 1 | | 193 | 235235 | 23 | 2011-02-10 12:17:05 | 1 | | 194 | 235235 | 1 | 2011-02-10 12:21:52 | 1 | | 195 | 235235 | 7 | 2011-02-10 12:21:52 | 1 | | 196 | 235235 | 13 | 2011-02-10 12:21:52 | 1 | | 197 | 235235 | 37 | 2011-02-10 12:21:52 | 1 | | 198 | 235235 | 23 | 2011-02-10 12:21:52 | 1 | | 199 | 235235 | 7 | 2011-02-10 12:22:26 | 1 | | 200 | 235235 | 37 | 2011-02-10 12:22:26 | 1 | | 201 | 235235 | 23 | 2011-02-10 12:22:26 | 1 | | 202 | 235235 | 7 | 2011-02-10 14:30:42 | 0 | | 203 | 235235 | 37 | 2011-02-10 14:30:42 | 0 | | 204 | 235235 | 23 | 2011-02-10 14:30:42 | 0 | +-----+-----------------+------------+---------------------+---------+ I did it this way beacuase it seems the easiest and fastest way. Otherwise I would have to lookup all the impacted_products from the table that match that notification_id and check 1) Was there a new product selected? If so, add it. 2) Was a product that was selected no longer selected? If so, delete it. 3) Was a product that was selected before still selected now? If so, leave it alone. This seemed like a lot of extra looping and a lot of extra DB queries to essentially end up at the same place. However, I feel that there has still got to be a more efficient way of doing this where I won't have all the extra entries in the impacted_products table. Any ideas? Thanks in advance! Hello, I'm just learning php (by force), but am pretty well versed in html and css. I did not rite the following code and I'm not sure how to pull out the php in the following in order to make the page validate. <tr> <td width="15%"><b><b>Priority</b></td> <td> <select name="priority" size="1" value="priority"> <option value="" <?php if ($row['priority'] == "") echo " selected";?> ></option> <option value="Normal" <?php if ($row['priority'] == "Normal") echo " selected";?> >Normal</option> <option value="Elevated" <?php if ($row['priority'] == "Elevated") echo " selected";?> >Elevated</option> <option value="STAT" <?php if ($row['priority'] == "STAT") echo " selected";?> >STAT</option> </select> </td> </tr> The idea is to prefetch the "priority" info and populate the drop down with that. Afterwards, the user can change the value and once submitted, the value will change in the database. Any pointers would be appreciated - and thanks in advance. Rich I'm new to this form and php/mysql so sorry if this isn't the right place to post this. This is what is in the first dropdown box. Code: [Select] $selValues['john'] = "a, b, c, d, e"; These are the different lists I want it to put in the second drop down box depending on what they choose in the first. Code: [Select] $selValues['list1']= " a1, a2, a3, a4, a5"; $selValues['list2']= " b1, b2, b3, b4, b5"; This is how I made an attempt to make it work before posting here. Along with plently of other ways. Code: [Select] if ($selValues['john']=a) { $chan_input = selectBuilder($selValues['$list1'] }; else if ($selValues['john']=b) { $chan_input = selectBuilder($selValues['$list2'] }; Basicly how I need it to work is there are two drop down boxes. First they will chose between a,b,c,d,e. If they chose a then on the second drop down box I only want them to be able to select a1,a2,a3,a4,a5. I understand that is might be something that is already answered and I apologize if it is, I could not find it.
What I need to do is build a simple form that has two options, they will be dropdown options. Dropdown A and Dropdown B then a Submit button. This part I understand in HTML, although it may be easier in php or javascript.
Then I need it to take the two options and create a "if/then" statement that loads a specific pdf that matches the two options selected.
Example.
If someone selects Option 1 from Dropdown A and Option 2 From Dropdown B then it loads 12.pdf If someone selects Option 5 from Dropdown A and Option 3 From Dropdown B then it loads 53.pdf If someone selects Option 2 from Dropdown A and Option 1 From Dropdown B then it loads 21.pdf and so on... It does not have to be the exact thing just some way to take both inputs and have it equal a specific pdf. Here is the form I built but I don't know what to put in the form_action.php file in order to make it work <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <center> <h1> Get Directions</h1> <form action="form_action.php" method="get" name="directions" target="_new"> <select name="startpoint" size="1"> <option value="north">North Tower Entrance</option> <option value="south">South Tower Entrance</option> <option value="moba">MOB A Entrance</option></select> -----> <select name="endpoint" size="1"> <option value="onco">Oncology</option> <option value="radio">Radiology</option> <option value="pulm">Pulmanary</option></select> <br /><br /> <input type="submit" value="Submit" /> </form> </center> </body> </html>Any help is appreciated, thanks. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=359241.0 I have a column in my db called 'Sold' which is set to Binary. I need a dropdown in my form, that converst the binary into 'True', 'False' for the options, and also selects the one that is set in the db. This is for an edit form, so will then need to adapt it for a add form. This is my code, which doesnt seem to be working <?php $id = $_GET["id"]; $sqlSold = "SELECT Sold FROM Products WHERE idProducts = $id;"; $products = [ 'True' => true, 'False' => false ]; ?> <select name="Sold"> <option selected="selected">Choose one</option> <?php foreach($products as $item){ echo "<option value='strtolower($item)'>$item</option>"; } ?> </select>
Hi,
I'm really at a loss here.
I have queried a table to get an option list, which returns what I expect but I need to then add it to some current code instead of the fixed option list presented.
The syntax is beyond me.
Please see attached.
Any pointers would be great.
Attached Files
OptionList.txt 1.61KB
7 downloads I'm doing a site for a used vehicles company. I have a "searchbar" with the following select options: the first one is to search per vehicle manufacturer (ex. BMW). The second one is for a price range (ex. any - $1 000 000). the third is per mileage (ex. any - 150 000). and the last one is per model (ex. 320). All of them are structured as drop-down selectors except for the last one "model" which is has a input type text. Here is what I struggle with... When I choose a manufacturer and click search then I get the desired results. But as-soon as I choose a value from the price or mileage or model I get all the values from the manufacturer, but it doesn't filter what I have chosen. Can you please help me.... Thank you Here is the code for the searchbar.php: Code: [Select] <?php ?> <form name="searchForm" action="showroom.php" method="GET" class="search"> <table cellpadding="0" cellspacing="0"> <tr class="search_bar"> <td><b>Search</b></td> <td><select name="make"> <?php do { ?><option value="<?php echo $row_make['Make']?>"<?php if (!(strcmp($row_make['Make'], $row_make['Make']))) {echo "selected=\"selected\"";} ?>> <?php echo $row_make['Make']?></option> <?php } while ($row_make = mysql_fetch_assoc($make)); $rows = mysql_num_rows($make); if($rows > 0) { mysql_data_seek($make, 0); $row_make = mysql_fetch_assoc($make); } ?> </select> </td> <td><select style="height:20px;" name="price"> <option>Price</option> <option value="">Any</option> <option value="5000">R5,000 </option> <option value="10000">R10,000 </option> <option value="15000">R15,000 </option> <option value="20000">R20,000 </option> <option value="25000">R25,000 </option> <option value="30000">R30,000 </option> <option value="35000">R35,000 </option> <option value="40000">R40,000 </option> <option value="45000">R45,000 </option> <option value="50000">R50,000 </option> <option value="55000">R55,000 </option> <option value="60000">R60,000 </option> <option value="65000">R65,000 </option> <option value="70000">R70,000 </option> <option value="75000">R75,000 </option> <option value="80000">R80,000 </option> <option value="85000">R85,000 </option> <option value="90000">R90,000 </option> <option value="95000">R95,000 </option> <option value="100000">R100,000 </option> <option value="125000">R125,000 </option> <option value="150000">R150,000 </option> <option value="175000">R175,000 </option> <option value="200000">R200,000 </option> <option value="225000">R225,000 </option> <option value="250000">R250,000 </option> <option value="275000">R275,000 </option> <option value="300000">R300,000 </option> <option value="325000">R325,000 </option> <option value="350000">R350,000 </option> <option value="375000">R375,000 </option> <option value="400000">R400,000 </option> <option value="425000">R425,000 </option> <option value="450000">R450,000 </option> <option value="475000">R475,000 </option> <option value="500000">R500,000 </option> <option value="600000">R600,000 </option> <option value="700000">R700,000 </option> <option value="800000">R800,000 </option> <option value="900000">R900,000 </option> <option value="1000000">R1,000,000 </option> </select> </td> <td><select style="height:20px;" name="mileage"> <option>Mileage</option> <option value="0_10000">0-10 000 km</option> <option value="10001_20000">10 001-20 000 km</option> <option value="20001_30000">20 001-30 000 km</option> <option value="30001_40000">30 001-40 000 km</option> <option value="40001_50000">40 001-50 000 km</option> <option value="50001_60000">50 001-60 000 km</option> <option value="60001_70000">60 001-70 000 km</option> <option value="70001_80000">70 001-80 000 km</option> <option value="80001_90000">80 001-90 000 km</option> <option value="90001_100000">90 001-100 000 km</option> <option value="100001_110000">100 001-110 000 km</option> <option value="110001_120000">110 001-120 000 km</option> <option value="120001">120 000km and above</option> </select></td> <td align="right"><b>Model:</b></td> <td><input type="text" name="model" /></td> <td><input type="submit" value="Search" /></td> </tr> </table> </form> I have set up a form page with a select box of colleges to select. I want the "options" in the select box to be values taken from a field called "name" in a table called "colleges" and they should be ordered alphabetically. I also want the default selected option to be "none." I have attached a picture to describe what i want. Please be detailed with the code. I am fairly new to php and mysql. Thank you. Hi, Im not sure whether this is a PHP or MySQL question, but im trying to get a select menu to only display the number of options that are defined in the mysql database.
For example
The code I have that retrieves the $quantity from the database.
Lets say that
$quantity = 3
Now I would like the option menu to only display three options, like this:
<select name="quantity"> <option value="<?php echo $quantity ?>"><?php echo 'Maximum of ' . $quantity . ' available'?></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select>but for example, if the $quantity was equal to 10 then I would like the menu to be displayed as such <select name="quantity"> <option value="<?php echo $quantity ?>"><?php echo 'Maximum of ' . $quantity . ' available'?></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select>How is it possible to do this? I am completely at a loss here. Many Thanks aquaman i want help on how to load a page inside a frame. As of right now I have values of 0 for the fields in champ_id as well as the con1_id, con2_id, and con3_id which is all fine. The end query returns 0 results which I understand however I'm trying to figure out that if the values in these fields is 0 then have it echo "Vacant" but i'm not sure if you can do a if statement inside a select statement. $query = "SELECT titles.titlename, titles.id, ( SELECT c.charactername FROM characters AS c WHERE c.id = champions.champ_id ) AS champion, ( SELECT c.charactername FROM characters AS c WHERE c.id = champions.con1_id ) AS con1, ( SELECT c.charactername FROM characters AS c WHERE c.id = champions.con2_id ) AS con2, ( SELECT c.charactername FROM characters AS c WHERE c.id = champions.con3_id ) AS con3 FROM champions INNER JOIN titles ON champions.title_id = titles.id"; Hi, I'm an novice/intermediate PHP prgogrammer, so excuse me if this is a stupid question. I have one php program that consist of a few functions. Inside the function taht is the starting point I pickup a few entries from a MYSQL database, and display those in my html page. I wish to dynamically put a link on those entries that makes it possible for the users to click those entries an get directed to other functions inside this very same PHP program WITH a parameter. The parameters that should accompany the url/link into the selected function to be able to select apropriate records from the mysql tables. Any hints and tips for this would be highly appreciated! Kind Regsrds, Terje Hvidsten. Hey guys, I am wanting to select a dropdown value based on the value of 'level' in the row of the user select by a $_GET. It will house the ranks of the user. Here is my script. RANK <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("chat"); $result = mysql_query("SELECT * FROM users WHERE user_id = '$_GET[id]'"); $row = mysql_num_rows($result); ?> <form id="main_form" name="main_form" method="post" action=""> <select name="rank"> <option value="0" <?php if($row['level']=="0") { echo "selected"; }?>>Unactivated</option> <option value="1" <?php if($row['level']=="1") { echo "selected"; }?>>Banned</option> <option value="2" <?php if($row['level']=="2") { echo "selected"; }?>>Regular User</option> <option value="3" <?php if($row['level']=="3") { echo "selected"; }?>>Donator</option> <option value="4" <?php if($row['level']=="4") { echo "selected"; }?>>Moderator</option> <option value="5" <?php if($row['level']=="5") { echo "selected"; }?>>Administrator</option> <option value="6" <?php if($row['level']=="6") { echo "selected"; }?>>Owner</option> </select> <input type="submit" id="main_submit" name="main_submit" value="submit" /> </form> It is not selecting for some reason at all. Can someone tell me what I am doing wrong? Hi I'm trying to create a form where people first select the number of children they have, and then a table should appear where they fill in the extra information (name, sex, dob) about every child. The code works except for that i don't know how to add the year of the date of birth of every child with a loop. Appartly i cannot use php in javascript? Any solutions? thanks! Code: [Select] function addKindForms(aantal) { if (aantal != "-") { var output = ""; output = output + "<table cellpadding='2' cellspacing='0'>"; output = output + "<tr><td><b>Naam:</b></td><td><b>Geslacht:</b></td><td><b>Geboortedatum:</b></td><td></td><td></td></tr>"; for(i=1;i<=aantal;i++) { output = output + "<tr><td><input type='text' name='kind"+i+"_name' size='15' value=''></td><td><select name='kind"+i+"_sex'><option value='m'>jongen</option><option value='f'>meisje</option></select></td><td><select name='kind"+i+"_gebdatumdag'><option value=''></option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'> 8</option><option value='9'>9</option><option value='10'>10</option> <option value='11'> 11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option></select></td><td><select name='kind'+i+'_gebdatummaand'><option value=''></option><option value='1'>jan</option><option value='2'>feb</option></select></td><td><select name='kind'+i+'_gebdatumjaar'><option value=''></option><?php for ($y=date('Y');$y>=(date('Y')-125);$y--){if($_POST['bdaykind_jaar']==$y){$selected='selected';}echo'<option value=''.$y.'' '.$selected.'>'.$y.'</option>';$selected = '';}?></select></td></tr>"; } output = output + "</table>"; document.getElementById("kindforms").innerHTML = output; } } I have the following code currently: Code: [Select] <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php print $item['view'] ?> <?php } ?> I would like to make the list a drop down with a link so that when a user selects, he goes to a new page. I tried the following: Code: [Select] <select name="select"> <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php $url = $node->field_buy_at[0]['url']; $store = $item['view']; ?> <? echo "<option value='$url'>$store</option>";?> <?php } ?> </select> I'm pretty sure it's this "$url = $node->field_buy_at[0]['url'];" that I don't have correct. Ive tried to create a function to create a dropdown select box but im getting alot of errors to do with the if statement saying the ($_POST[$name]) value is not set??? function selectBox($name, $firstvalue, $limit, $increment) { // echo "<br>"; // echo $name; // echo "<br>"; // print_r($_POST[$name]); // echo "<br>"; $select ="selected=\"selected\""; $body = "<select name='$name' id='$name' method='POST'> <option value=''>$name</option>"; for ($value = $firstvalue; $value <= $limit; $value += $increment) { $body .= "<option value= '$value' "; if ($_POST["$name"] === $value) { $body .= $select; } $body .= ">$value</option>"; } $body .= "</select>"; // echo $value; // echo $_POST[$name]; // echo $_POST['Width']; return $body; } Any help would be greatly appreciated This seems to be a bit of a challenge but I am creating a multiple page form and on one of the pages I have a select field. I would like the user to have the ability to select multiple options but I am using some functions to move the data in hidden fields from page to page. I don't think my functions are jiving with my my foreach loop cause I keep getting an invalid argument error. Thanks in advance for any help. Here is my function: function setSelected($fieldName, $fieldValue) { if(isset($_POST[$fieldName]) && $_POST[$fieldName] == $fieldValue) { echo 'selected="selected"'; } } And here is my loop: $selections = ""; if(isset($_POST["selections"])) { foreach ($_POST["selections"] as $selection) { $selections .= $selection . ", "; } } I'm trying to pull up an identical form after submission by using its "id" and ECHO for the form lines. Question: What is the correct approach for ECHOing an HTML dropdown that is written as: <select name='chixcutlet' value='' > <option value='0.00' selected> --- </option> <option value='1.00'> 1 </option> <option value='2.00'> 2 </option> <option value='3.00'> 3 </option> </select> I want it to get the info from the database so that the option that is saved in the database will be new default when the page is loaded. If I don't change it to the previous info it will update the database with the default option rather then the actual option. Is it possible to have a loop inside a mysql select statement? If yes, can someone please give me an idea. |