Dark-Hawk Posted May 27, 2009 Share Posted May 27, 2009 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! Quote Link to comment Share on other sites More sharing options...
Dark-Hawk Posted May 27, 2009 Author Share Posted May 27, 2009 Also any advice on splitting it, I'm presuming I'll have to use preg_match()? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 <?php $hour1 = 1; $minute1 = 30; $hour2 = 4; $minute2 = 55; $range_time = $hour1 . ':' . $minute1 . '-' . $hour2 . ':' . $minute2; echo $range_time; You messed up your strings. Quote Link to comment Share on other sites More sharing options...
Dark-Hawk Posted May 27, 2009 Author Share Posted May 27, 2009 I actually just figured that part out right as you posted, thanks! Any idea on then splitting it up when I pull it from the DB? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 What do you mean splitting them up? Quote Link to comment Share on other sites More sharing options...
Dark-Hawk Posted May 27, 2009 Author Share Posted May 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 Uh, I didn't change the value of $hour1, $hour2, $minute1 or $minute2. If you echo them, you still get the original value. :-\ So there's no need to split them back up. The original variables never changed values. Quote Link to comment Share on other sites More sharing options...
Dark-Hawk Posted May 27, 2009 Author Share Posted May 27, 2009 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... Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 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]; Quote Link to comment Share on other sites More sharing options...
Dark-Hawk Posted May 27, 2009 Author Share Posted May 27, 2009 I'll keep that in mind and possibly just store them in separate tables due to the way the script will be running. Thanks though! Quote Link to comment 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.