Jump to content

Huge drop down box


Shadowing

Recommended Posts

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>

?>

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

?>

Link to comment
Share on other sites

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 . . .

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.