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
https://forums.phpfreaks.com/topic/159855-solved-combinging-variables/
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?

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

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

Archived

This topic is now archived and is closed to further replies.

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