phppup Posted February 23, 2012 Author Share Posted February 23, 2012 I see what you mean. Made the change, but still no difference. The DB field is VARCHAR and displays x.xx for value. When I changed back to ZERO as the comparison, my result shifts to 10. Don't know why. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320503 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 Without being able to test things it's hard to say. Try without single quotes 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/3/#findComment-1320505 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 Took out the single quote: 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>"; result in dropdown still at zero :-( What else would you test. AT this point, I'll give you the whole damn thing.. LOL Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320508 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 What do you see if you just echo out the query (not in selection area)? echo "{$array['roastturkey'] }"; Are you seeing expected value? //Edit Here's a little "stand-alone" script. <?php $values = range('0.00', '10.00'); //for testing// $array=array('roastturkey' => '5.00'); // 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/3/#findComment-1320509 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 The statement you provided does nothing. But when I use echo "There are " . $row['roastturkey'] ." servings"; inside my table, it provides the correct values (even when the ID is changed) Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320511 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 Are you using $row or $array? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320512 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 In my table I'm using $row. Not too familiar with arrays (which is also why I hardcoded initially, as I didn't know that there was a simpler way with PHP) Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320513 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 Can you show query statement you are using to grab info from DB? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320515 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2012 Share Posted February 23, 2012 Actually, just post all your current code, starting from where you are forming the mysql query statement through to the end of the <select></select> menu code. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320517 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 $result = mysql_query("SELECT * FROM mytest WHERE id = '4' ") and I change the ID accordingly, hoping for a different and accurate result, which hasn't happened. Note: everything is connecting etc, as I have an alternate page WITHOUT the dropdown scenario and it runs fine, echoing all accurate data. I thought this would be an easy way to update info, can you think of a better method in case this issue is unresolveable. Although I don't think I'm the first to attempt this method. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320518 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 I'll let the big-boys respond. In the mean time, post entire code as was requested. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320519 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 $result = mysql_query("SELECT * FROM pass WHERE id = '4' ") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo "There are " . $row['roastturkey'] ." servings"; // this verifies that i CAN get the data echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Comment</th> <th>Email Address</th></tr>"; //took from another table just to get headings and columns echo "<tr><td>"; echo "<select name='roastturkey'>"; echo "<option value='0.00' " . ($row['roastturkey'] == 0.00 ? 'selected="selected"' : '') . ">0</option>"; echo "<option value='1.00' " . ($row['roastturkey'] == 1.00 ? 'selected="selected"' : '') . ">1</option>"; echo "<option value='2.00' " . ($row['roastturkey'] == 2.00 ? 'selected="selected"' : '') . ">2</option>"; echo "<option value='3.00' " . ($row['roastturkey'] == 3.00 ? 'selected="selected"' : '') . ">3</option>"; echo "<option value='4.00' " . ($row['roastturkey'] == 4.00 ? 'selected="selected"' : '') . ">4</option>"; echo "<option value='5.00' " . ($row['roastturkey'] == 5.00 ? 'selected="selected"' : '') . ">5</option>"; echo "<option value='6.00' " . ($row['roastturkey'] == 6.00 ? 'selected="selected"' : '') . ">6</option>"; echo "<option value='7.00' " . ($row['roastturkey'] == 7.00 ? 'selected="selected"' : '') . ">7</option>"; echo "<option value='8.00' " . ($row['roastturkey'] == 8.00 ? 'selected="selected"' : '') . ">8</option>"; echo "<option value='9.00' " . ($row['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/3/#findComment-1320520 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 Note: had EVERYTHING as ARRAY... just switched them to $row on a hunch that didn't work. I'll put them back to $array Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320521 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 I GOT IT!!!!! Noticed that i missed the array in option 10, called it $row, and SUCCESS! Thank you EVERYONE for persevering. If there are any tweaks to my code, please let me know. And if someone can let me know whether I would be BETTER off using arrays, please guide me to the difference of $row versus $array. Thanks sooo much again! Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320522 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 Normally you would use mysql_fetch_row for grabbing info from one "row" of the table. $row = mysql_fetch_row( $result ); If you are listing a group of rows you would use while ($row =mysql_fetch_array( $result )){ //and result will loop for each record } There are other options as well. Change to use mysql_fetch_row. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320523 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2012 Share Posted February 23, 2012 $row and $array are just two different names you have chosen to use as variables names in your code. They are both arrays. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320525 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 So, $row = mysql_fetch_array is forcing the DB to do more work than it needs to by scanning the entire DB? And fetch_row directs it more definitively?? Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320526 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 $row and $array are just two different names you have chosen to use as variables names in your code. They are both arrays. Exactly. You could name the variable $meat or any other name. $meat = mysql_fetch_row( $result ); echo "{$meat['roastturkey']}"; Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320528 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 So, $row = mysql_fetch_array is forcing the DB to do more work than it needs to by scanning the entire DB? Doing more work, Yes. Not scanning entire DB. And fetch_row directs it more definitively?? Yes Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320529 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 ie: $meat.... yes, i played with that early on in my PHP endeavors. everything was so structured, and then I scratched my head and started naming items with names like sasperilla and heebeeegeeebeees. It was confusinig, but it DID work... LOL So in actuality, DB fatigue not withstanding, fetch_array is just a bit more generic, and kinda ensures that it'll locate what the fuction is looking for by casting a wider net, so to speak. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320530 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2012 Share Posted February 23, 2012 So, $row = mysql_fetch_array is forcing the DB to do more work than it needs to by scanning the entire DB? And fetch_row directs it more definitively?? Nope. That's not what is different between the different mysql_fetch_xxxxx functions. You need to read the php.net documentation for the functions. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320531 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 OK. So now all I need to do is build this page into a form, and have the 'action' point to a PHP page that connects and the run UPDATE * FROM mytable WHERE id = 'this-record' Uh oh, is this a new thread... LOL Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320532 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 OK. So now all I need to do is build this page into a form, and have the 'action' point to a PHP page that connects and the run UPDATE * FROM mytable WHERE id = 'this-record' Uh oh, is this a new thread... LOL Piece of cake. Post new topic if you need help. Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320533 Share on other sites More sharing options...
phppup Posted February 23, 2012 Author Share Posted February 23, 2012 Thanks again to everyone. I'm gonna mark this one resolved! Quote Link to comment https://forums.phpfreaks.com/topic/257560-retrieving-an-html-dropdown-select/page/3/#findComment-1320534 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.