scootstah Posted February 22, 2012 Share Posted February 22, 2012 You would need to concatenate the ternary statement. echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320224 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 I'm plugging it in now. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320228 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 EUREEEEEEKAH!!!! IT WORKED!!!! *hugs & kisses* JUMPS for JOY!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320230 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 oops! maybe not. But I think I may be able to fix it... keep you posted. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320231 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 Nope! It's populating the dropdown with 10 lines of: selected="selected">0 Not the value that the table has. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320233 Share on other sites More sharing options...
scootstah Posted February 22, 2012 Share Posted February 22, 2012 Because that was pseudo test code, you need to put the real value from the database into the ternary statement. So replace $array['wings'] with whatever the column is from your database. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320238 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 That was the first thinig I did. I mean, I'm not totally ignorant. I switched a few numbers and this is what I have now: echo "<tr><td>"; echo "<select name='roastturkey'>"; echo "<option value='0.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td rowspan='2'>ROAST TURKEY</span></td><td rowspan='2'>7.00 LB</span></td> "; The drop down shows as follows: 0 1 selected="selected">2 selected="selected">3 selected="selected">4... etc. And the database quierie after connecting is: $result = mysql_query("SELECT * FROM pass WHERE id = '4' ") Record 4 has 10 as the value for the 'roastturkey'. I've changed it to record 5 which has a value of 5, but the dropdown does NOT change. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320243 Share on other sites More sharing options...
scootstah Posted February 22, 2012 Share Posted February 22, 2012 You need to check that the value matches the value of the option tags. echo "<option value='0.00' " . ($array['roastturkey'] == '0.00' ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == '1.00' ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00'> " . ($array['roastturkey'] == '2.00' ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00'> " . ($array['roastturkey'] == '3.00' ? 'selected="selected"' : '') . ">3</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320244 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 OKAY, the dropdown is now populated with number from 0 thru 10. The database quierie after connecting is: $result = mysql_query("SELECT * FROM pass WHERE id = '4' ") Record 4 has 10 as the value for the 'roastturkey'. I've changed it to record 5 which has a value of 5, Yet the dropdown STILL does NOT change to reflect the stored value in the database :-( Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320246 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 ???? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320249 Share on other sites More sharing options...
scootstah Posted February 23, 2012 Share Posted February 23, 2012 You'll have to hard refresh the page, so hit ctrl+f5. Or, you could look at the source to see if the HTML is correct. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320250 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 I've been refreshing ALL day. I have a dropdwon menu coded as follows" echo "<tr><td>"; echo "<select name='roastturkey'>"; echo "<option value='0.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td rowspan='2'>ROAST TURKEY</span></td><td rowspan='2'>7.00 LB</span></td> "; And a database quierie after connecting is: $result = mysql_query("SELECT * FROM pass WHERE id = '4' ") 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 form page is loaded, and will SHOW in the form. If I don't change it to the previous info it will update the database with the default option rather then the actual option when re-submitted. Record 4 has 10 as the value for the 'roastturkey'. I've changed it to record 5 which has a value of 5, but the dropdown does NOT change. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320254 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 OKAY, so I managed to get a 5 in as the dropdown default for record number 4. Now I changed my quiery to record number 5, but the dropdown seems STUCK on 10. The value for record 4 for 'roastturkey' is FIVE. Any ideas??? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320267 Share on other sites More sharing options...
scootstah Posted February 23, 2012 Share Posted February 23, 2012 You still haven't changed the comparison value. echo "<option value='0.00' " . ($array['roastturkey'] == '0.00' ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == '1.00' ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00'> " . ($array['roastturkey'] == '2.00' ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00'> " . ($array['roastturkey'] == '3.00' ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00'> " . ($array['roastturkey'] == '4.00' ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00'> " . ($array['roastturkey'] == '5.00' ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00'> " . ($array['roastturkey'] == '6.00' ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00'> " . ($array['roastturkey'] == '7.00' ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00'> " . ($array['roastturkey'] == '8.00' ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00'> " . ($array['roastturkey'] == '9.00' ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00'> " . ($array['roastturkey'] == '10.00' ? 'selected="selected"' : '') . ">10</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320284 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 I haven't changed the comparison value because I don't know where or how or to what... silly me :-) As a matter of fact, what I probably did throughout the process was to change it inaccuratley. So, what's my next step please? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320437 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 You've been given MANY examples. <?php //It is assumed that you have the table field called `roastturkey` and holds a numeric value and you are querying table `pass` with test id 4. $query = "SELECT roastturkey FROM pass WHERE id = '4'"; $result = mysql_query($query); $array = mysql_fetch_assoc($result); $values = range(0, 10); echo "<select name=\"my_field\">\n"; foreach($values as $v) { echo "<option value=\"$v\" " . ($array['roastturkey'] == $v ? 'selected="selected"' : '') . ">$v</option>"; } echo "</select>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320465 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 Correct! Although the dropdown is hardcoded as: echo "<option value='0.00' " . ($array['roastturkey'] == '0.00' ? 'selected="selected"' : '') . ">0</option>";echo "<option value='1.00' " . ($array['roastturkey'] == '1.00' ? 'selected="selected"' : '') . ">1</option>";echo "<option value='2.00'> " . ($array['roastturkey'] == '2.00' ? 'selected="selected"' : '') . ">2</option>";echo "<option value='3.00'> " . ($array['roastturkey'] == '3.00' ? 'selected="selected"' : '') . ">3</option>";echo "<option value='4.00'> " . ($array['roastturkey'] == '4.00' ? 'selected="selected"' : '') . ">4</option>";echo "<option value='5.00'> " . ($array['roastturkey'] == '5.00' ? 'selected="selected"' : '') . ">5</option>";echo "<option value='6.00'> " . ($array['roastturkey'] == '6.00' ? 'selected="selected"' : '') . ">6</option>";echo "<option value='7.00'> " . ($array['roastturkey'] == '7.00' ? 'selected="selected"' : '') . ">7</option>";echo "<option value='8.00'> " . ($array['roastturkey'] == '8.00' ? 'selected="selected"' : '') . ">8</option>";echo "<option value='9.00'> " . ($array['roastturkey'] == '9.00' ? 'selected="selected"' : '') . ">9</option>";echo "<option value='10.00'> " . ($array['roastturkey'] == '10.00' ? 'selected="selected"' : '') . ">10</option>"; So when I test the script it appears to work and shows 10 as the quntity for roastturkey. Yet when I change the quiery to a differnt ID=x, the quantity of 10 remains (as if frozen). The DB has a variety of qunatities in it with varying IDs just for testing. So the script FAILS because the quantity never changes from 10. Ideas??? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320473 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 DON'T HARD CODE OPTIONS. In my example, the number of selection options is defined here. $values = range(0, 10); If you need to COUNT the number of options for a particular product then run a separate query to do so then change the number of options. Not knowing where or how you are storing this information makes it impossible to give working answer but it would be something like this. $countturkey = mysql_query("SELECT COUNT(*) as ct FROM products WHERE item='turkeybreast'"); WHILE($cntturkey = mysql_fetch_array($countturkey)) { $ct = $cntturkey['COUNT(ct)']; } $values = range(0, $ct); The "Selected" option should be showing based on query with the user `id`, which I believe we all thought was the problem you were having. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320476 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 You need to READ the 3 pages prior. NOTHING is being COUNTED. There is data in a DB. I can easily view it in a browser. Now I want to have the same data populated into the numerous dropdown selections so the information resembles that which was ORIGINALLY submitted AND become the NEW DEFAULT VALUES so that THIS form can be submitted to UPDATE or CHANGE any of the data. That's the entire project. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320481 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 Well reply #40 should do that. If value for `roastturkey` is 5 then option 5 should be the selected option in dropdown. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320482 Share on other sites More sharing options...
Psycho Posted February 23, 2012 Share Posted February 23, 2012 You need to READ the 3 pages prior. NOTHING is being COUNTED. No, YOU need to take a step back and understand what is being said. You have a select list of 10 options where the only difference is that the value/display is going from 0.00/0 to 10.00/10. Hard coding those options is just plain stupid. Drumming provided some code that would dynamically create those options AND auto-select the appropriate option based upon the previously selected value. Which you were told to do back on page 1 of this thread. You OBVIOUSLY didn't even try it. However, there was one difference in what his code would produce and what you currently have. The values would be 0, 1, 2 ... instead of 0.00, 1.00, 2.00, if that is really necessary that can be easily fixed. Here is my suggestion //Get the ID of the record being displayed //Variable name is just an example, replace with whatever you are using $recID = (int) $_GET['id']; //Get the currently selected value from the DB based upon the record //-- This assumes you need all the data for the record to display on the page //-- otherwise you would change the query for only the fields you need //-- The value of 'roastturkey' for the record will be used to auto-select the correct option $query = "SELECT * FROM pass WHERE id = '4'"; $result = mysql_query($query); $record = mysql_fetch_assoc($result); //Create a loop to generate ALL the select options using the value of //$recod['roastturkey'] to auto-select the record's current value $optionValues = range(0, 10); //Create an array of values from 0 to 10 echo "<select name=\"my_field\">\n"; foreach($optionValues as $val) { //Create a selected variable to set for each option $selected = ($val==$record['roastturkey']) ? ' selected="selected"' : ''; $decVal = number_format($val, 2); //Format value with decimals if required echo "<option value='{$decVal}'{$selected}>{$val}</option>\n"; } echo "</select>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320483 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 FULL STORY REPEATED: A form inputs data into several fields named turkey, roastbeef, spinach, potatoes, etc (i'll stop bc it's lunchtime now... LOL). Input process is FINE. Now DB has several entries with varying quantiities in each. Record A has 5 (orders) of turkey and 2 spinach Record B has 3 (orders) of roast beef and 1 spinach, and 2 potaoes, etc. Any item NOT ordered has a DEFAULT of ZERO. I can successfully view all orders in a browser... NO PROBLEM. Now I have a SECOND form (identical to the first) and I want to ECHO the values into it. I want those values to appear INSIDE the dropdown with the info from the database so that the option that is saved in the database will be new default when the form page is loaded, and will SHOW in the form so that if customer A decides that 5 orders of turkey is too much, then the order can be UPDATED to the DB with the NEW VALUE. If I don't change it to the previous info it will update the database with the default option rather then the actual option when re-submitted. My SECOND form has a dropdwon menu coded as follows" echo "<tr><td>"; echo "<select name='roastturkey'>"; echo "<option value='0.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">10</option>"; echo " </select></td><td rowspan='2'>ROAST TURKEY</span></td><td rowspan='2'>7.00 LB</span></td> "; and I am currently using the statement: $result = mysql_query("SELECT * FROM mytablename WHERE id = '5' ") just to get a value for testing purposes. Then I change the ID within the statement to check the functionality. At first, there was NO SUCCESS. Yesterday, I got the dropdown's value to change to 10 (which was valid). But NOW the dropdown has 'adopted' 10 as the default, as it does NOT CHANGE when I alter the ID value to orders that contain a value that is NOT 10 in them. Any solutions? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320484 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 echo "<option value='0.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00'> " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">10</option>"; And were you not told that you need to change comparison values for each of these options? If you are storing values in DB as 7.00 for example, the HARDCODED line would be. echo "<option value='7.00'> " . ($array['roastturkey'] == '7.00' ? 'selected="selected"' : '') . ">7</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320486 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 I've changed it from: echo "<option value='0.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($array['roastturkey'] == 0 ? 'selected="selected"' : '') . ">10</option>"; to echo "<option value='0.00' " . ($array['roastturkey'] == '0' ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($array['roastturkey'] == '1' ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($array['roastturkey'] == '2' ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($array['roastturkey'] == '3' ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($array['roastturkey'] == '4' ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($array['roastturkey'] == '5' ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($array['roastturkey'] == '6' ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($array['roastturkey'] == '7' ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($array['roastturkey'] == '8' ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($array['roastturkey'] == '9' ? 'selected="selected"' : '') . ">9</option>"; echo "<option value='10.00' " . ($array['roastturkey'] == '10' ? 'selected="selected"' : '') . ">10</option>"; and now I get ZERO for all the ID's that I query. The INITIAL default value is ZERO. Then the value changes when the data is submitted though the form initially and posted into the DB. Does the value that is input need to be coompared. Does the hardcoding need to be altered for every instance AFFTER the data is recorded? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320497 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 See how you have the option "value" listed as 1.00, 2.00 etc? Is that how values are stored in DB? Then the comparison needs to match. Does 5.00 == '5' ? It could in some cases but you want to look for exact match as in 5.00 == '5.00'. echo "<option value='5.00' " . ($array['roastturkey'] == '5.00' ? 'selected="selected"' : '') . ">5</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/2/#findComment-1320501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.