Jump to content

[SOLVED] Combinging variables?


Dark-Hawk

Recommended Posts

I'm having a little difficulty combining these variables. Just a test I set this up. I have 4 drop down boxes to select a particular time to set the range it will be displayed, however when it uploads to the database I need it to upload in the range like 1:30-4:55 for instance rather than uploading to 4 separate tables.

 

<?
$hour1 = 1;
$minute1 = 30;
$hour2 = 4;
$minute2 = 55;

$range_time = echo "$hour1 . ":" . $minute1 . "-" . $hour2 . ":" . $minute2";

echo "$range_time";
?>

 

Once doing the actual range I'll just split it all back up at the :'s and -'s. Thanks for the help in advance!

Link to comment
Share on other sites

Sorry, so after combining the two times, they will go into one table on a database in the format of the aforementioned final variable. However, the range for the time is merely used to allow people to sign up in that given time range for an event. Thus, I'll need to take it once again and have it as hour1, hour2, minute1 and minute2 to keep the range properly set in a drop down box. Subsequently it'll give people incremental values of every 10 minutes that they can sign up in that time range ... I'm hoping that makes sense?

Link to comment
Share on other sites

Yeah I know, you're missing what I'm saying though... Once they're in the table it will ONLY be the range of all of them combined, thus I wont be able to reference back to $hour1, $hour2, etc. For an entirely different part of the script I will need to split them back into the initial 4 variables...

Link to comment
Share on other sites

I would seriously look into DB design. You shouldn't store time as a string.

 

But if you want you can use regex or just splitting the string.

<?php
$str = '1:30-4:55';
$times = explode('-',$str);
$time1 = explode(':',$times[0]);
$time2 = explode(':',$times[1]);

$hour1 = times1[0];
$hour2 = times2[0];
$minute1 = times1[1];
$hour2 = times2[1];

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.