Shadowing Posted December 18, 2011 Share Posted December 18, 2011 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 <?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> ?> Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/ Share on other sites More sharing options...
sw0o0sh Posted December 19, 2011 Share Posted December 19, 2011 Store the options in an array and loop through them to output or implode Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1299264 Share on other sites More sharing options...
Ivan Ivković Posted December 20, 2011 Share Posted December 20, 2011 Store an array in a seperate file with all the data, then include it. arrays.php : $gmt[0]['value'] = -1200; $gmt[0]['label'] = '(GMT -1200) International Date Line West'; $gmt[1]['value'] = -1100; $gmt[1]['label'] = '(GMT -1100) Coordinated Universal Time -11'; And so on... In your listout file: include('arrays.php'); echo '<select name=\'cars\'>'; foreach($gmt as $option){ echo '<option value="{$option['value']}">'. $option['label'] .'</option>'; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1299587 Share on other sites More sharing options...
Ivan Ivković Posted December 20, 2011 Share Posted December 20, 2011 Oops, I messed up something since I don't use this type of manual typing of code - now tested, works: echo '<select name=\'cars\'>'; foreach($gmt as $option){ echo "<option value='{$option['value']}'>". $option['label'] ."</option>"; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1299592 Share on other sites More sharing options...
Shadowing Posted December 20, 2011 Author Share Posted December 20, 2011 Thank you so much for explaining this to me in detail Ivkovic. this is going to teach me alot how to do a array I just started on it will let you know my progress. going to take me some time to make the array i have 101 of these to do lol. Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1299894 Share on other sites More sharing options...
Shadowing Posted December 20, 2011 Author Share Posted December 20, 2011 Alright got my array all done im acctually trying to insert the -1200 part into the data base <?php mysql_query("UPDATE users SET time_offset= '".mysql_real_escape_string($_POST['reason'])."' WHERE id = '".mysql_real_escape_string($_SESSION['user_id'])."'"); ?> how would I go about doing that Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1299939 Share on other sites More sharing options...
Shadowing Posted December 21, 2011 Author Share Posted December 21, 2011 I'm completly stuck on this Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300189 Share on other sites More sharing options...
Psycho Posted December 21, 2011 Share Posted December 21, 2011 Just reference the select field in the POST/GET data. If the field is named 'cars' (as in your original post) you would use $time_offset = intval($_POST['cars']); $user_id = intval($_SESSION['user_id']); $query = "UPDATE users SET time_offset= '{$time_offset}' WHERE id = '{$user_id}'"; $result = mysql_query($query); You do not need to use mysql_real_escape_string() on the value since you need to validate the value as an integer. mysql_real_escape_string() is for string data. Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300194 Share on other sites More sharing options...
Pikachu2000 Posted December 21, 2011 Share Posted December 21, 2011 Someone correct me if I'm mistaken, but I think this approach is somewhat wrong. The offset wouldn't be 1100 hours or -0400 hours, it would be 11 hours or -4 hours. Storing 1100 or -0400 in the database, IMO isn't the best way to do it. What do you store for Newfoundland Standard Time zone, where the offset is -3.5 hrs? Do you store -0330? Storing the offset in the that format isn't practical unless you add the additional overhead of another function to convert the value from -0330 to -3.5. If you store the value as a decimal number, you can do the calculation easily in the query string and directly output the time, no? SELECT DATE_ADD( UTC_TIME(), INTERVAL `offset_field` HOUR ) AS field_alias Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300201 Share on other sites More sharing options...
Psycho Posted December 21, 2011 Share Posted December 21, 2011 Personally, I found that offsets to GMT are typically represented as -0400, +1200, etc. Plus, if you convert to a fraction you kind of lose some "visual acuity". I've seen people mistake 5.15 with 5 hours and 15 minutes (instead of 5 hours, 9 minutes). But, if you use 5:09 or 5:15 it is completely obvious. And, with one tweak, you can easily use those value to generate the offset using the query. Just use a semi-colon in the value: "-09:00", "12:00". Then using the same logic Pikachu2000 provided just use the "HOUR_MINUTE" inteterval type SELECT DATE_ADD( UTC_TIME(), INTERVAL `offset_field` HOUR_MINUTE ) AS field_alias Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300265 Share on other sites More sharing options...
Shadowing Posted December 21, 2011 Author Share Posted December 21, 2011 I really should stop assuming stuff lol. I was making the drop down box way more complicated then what it was I guess i didnt realize it would store the -1200 in the data base. I was thinking it would store (GMT -1200) International Date Line West which it doesnt. so that part is all solved I tested this and it works i also tested -0630 and I use +0000 for GMT <?php date_default_timezone_set('UTC'); $new = date('m/d/Y/H:i:s', strtotime("-0600")); echo $new; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300269 Share on other sites More sharing options...
Pikachu2000 Posted December 22, 2011 Share Posted December 22, 2011 Personally, I found that offsets to GMT are typically represented as -0400, +1200, etc. Plus, if you convert to a fraction you kind of lose some "visual acuity". I've seen people mistake 5.15 with 5 hours and 15 minutes (instead of 5 hours, 9 minutes). But, if you use 5:09 or 5:15 it is completely obvious. The value= attribute doesn't have to be the same as what's displayed to the user . . . Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300285 Share on other sites More sharing options...
Shadowing Posted December 22, 2011 Author Share Posted December 22, 2011 sigh i just notice something. I really thought I had this working. This is making it exactly 12 hours off. instead of being 6pm its 6am. UTC must not be what im wanting to set it to for default I didnt notice it earlier cause i forgot its displaying military time always lol. so when it read -6pm it should of been saying 18 date_default_timezone_set('UTC'); $new = date('m/d/Y/H:i:s', strtotime("-0600")); also want to mention that just typing -6 gives the same results +6 is giving what -6 should be wierd Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300293 Share on other sites More sharing options...
Shadowing Posted December 22, 2011 Author Share Posted December 22, 2011 lol what i was doing wasnt working at all i alos notice eastern time was one hour behind instead of ahead. So now im going back to using seconds against time $new = date('m/d/Y/H:i:s', time()-21600); which equals -6 Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300316 Share on other sites More sharing options...
Psycho Posted December 22, 2011 Share Posted December 22, 2011 Personally, I found that offsets to GMT are typically represented as -0400, +1200, etc. Plus, if you convert to a fraction you kind of lose some "visual acuity". I've seen people mistake 5.15 with 5 hours and 15 minutes (instead of 5 hours, 9 minutes). But, if you use 5:09 or 5:15 it is completely obvious. The value= attribute doesn't have to be the same as what's displayed to the user . . . I wasn't referring to the displayed value to the user. From a programmatic viewpoint I would prefer to use +0430 rather than 4.5. Even the PHP date() function uses that format for displaying the timezone offset: date('O'); // +0200 date('P'); // +02:00 Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300341 Share on other sites More sharing options...
Pikachu2000 Posted December 22, 2011 Share Posted December 22, 2011 Oh, from the context, it seemed that you were referring to the visible value. Quote Link to comment https://forums.phpfreaks.com/topic/253439-huge-drop-down-box/#findComment-1300386 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.