jmr3460 Posted November 30, 2009 Share Posted November 30, 2009 I have exploded a string as such: $time = "20:30"; $times = explode(':', $time); $hour = $times[0];//line 53 $minute = $times[1];//line 54 I am getting this notice:Notice: Undefined offset: 1 in /home/arscnaor/public_html/meeting/admin/update_meeting.php on line 54 First of all what is offset? Second why did I not get a notice on line 53? By the way 20:30 is a varchar in my database table. Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/ Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 Basically $times doesn't have a second item in the array, so $minute can't be set, the code you posted will work but your get the error if $time was "20" So can you post the code where you set $time EDIT: oh a quick fix would be, to check it first then set a default of 00 ie $hour = (isset($times[0]))?$times[0]:"00";//line 53 $minute = (isset($times[1]))?$times[1]:"00";//line 54 Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967789 Share on other sites More sharing options...
jmr3460 Posted November 30, 2009 Author Share Posted November 30, 2009 $sql_meeting = "SELECT * FROM meeting WHERE meeting_id = '$meeting_id' AND del = 0"; $query_meeting = mysql_query($sql_meeting) or trigger_error(mysql_error()); $result_meeting = mysql_fetch_array($query_meeting); $day = $result_meeting['day']; $time = $result_meeting['time']; $split_time = explode(':', $time); $hour = $split_time[0];//line 53 $minute = $split_time[1];//line54 Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967790 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 Okay it would seam that not all of the data the field time in the database has a colon (, a simple fix is in my last post Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967798 Share on other sites More sharing options...
jmr3460 Posted November 30, 2009 Author Share Posted November 30, 2009 I tried the quick fix and now my $hours is not jiving with my code below. This is form to update some information from a database. In my table my column it called time it is a varchar though. This value was created by this line for insertion as a string. $time= $hour . ":" . $minute; Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967803 Share on other sites More sharing options...
jmr3460 Posted November 30, 2009 Author Share Posted November 30, 2009 I am going to try and change my database column to a date format and insert it as such to see what that does. That got rid of the notice, but the value is not recognized. My $selected variable is not working. since the notice is gone I am thinking that thee is a value in my array not. <select name=\"minute\">"; $minutes = array('00', '15', '30', '45'); foreach($minutes as $minut){ if($minut == $minute){ $selected = "selected"; } else { $selected = ""; } echo "<option value=\"" . $minut . "\"" . $slected . ">" . $minut . "</option>"; } echo "</select> Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967809 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 if your pulling from a date & timestamp then your probably have to update the code like so date_default_timezone_set('Etc/GMT'); //I'm in the UK but change to yours $time = strtotime($result_meeting['time']); $hour = date("H",$time); $minute = date("i",$time); Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967817 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 First setup a field as a TIME field now PHP time to mysql <?php date_default_timezone_set('Etc/GMT'); $hour = 22; $minute = 33; $phptime = mktime($hour, $minute, 0); //create time $mysqltime = date("H:i:s", $phptime); //format as MySql //use $mysqltime to insert into database //lets assume $mysqltime has been pulled from the database $time = strtotime($mysqltime); //convert to unix $hour = date("H",$time); //get Hour $minute = date("i",$time); //Get Minues Hope that scared helped you Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967823 Share on other sites More sharing options...
jmr3460 Posted November 30, 2009 Author Share Posted November 30, 2009 OK I echoed my $minute and it echoed the correct minute (30) I need to set my variable $selected now so that it is equal to selected for the value on my option loop. this is what I have now: echo "</select><select name=\"minute\">"; $minutes = array('00', '15', '30', '45'); foreach($minutes as $minut){ if($minut == $minute){ $selected = "selected"; } else { $selected = ""; } echo "<option value=\"" . $minut . "\"" . $slected . ">" . $minut . "</option>"; } echo "</select>"; Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967839 Share on other sites More sharing options...
jmr3460 Posted November 30, 2009 Author Share Posted November 30, 2009 I guess I should learn to read and spell. I misspelled my $selected variable in my loop. Thanks for all your help MadTechie. I really try to find the answer from php.net and most of the time I do. I know you guys help a lot of addict and I only come here when I can't find the answer anywhere else. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967847 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 I'm sorry but i am not sure of the actual question.. My last post gives an example of converting hour and minutes to PHP time and then to SQL time then back to hour and minutes Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967852 Share on other sites More sharing options...
jmr3460 Posted November 30, 2009 Author Share Posted November 30, 2009 I was trying to tell you thank you Mat Techie. You helped me fix my first problem and my second problem was from me misspelling a variable. I am very grateful for this website. I was also saying that I know you guys help a lot of people with this php. I get a lot of help. I just wanted to say that I try and find the problem from other sources before I come here. I thought I read that somewhere on this site. The right way to ask a question (of which I am still learning that obviously) and trying to find the answer somewhere else (google, ect.) I hope to be able to help people on this site one day. I look at some of the other post and when I do post I usually find out how much I have to learn. I will keep on coding and I will get there some day. By the Way Your last code fixed the problem. Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967914 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 I was trying to tell you thank you Mat Techie Who's Mat ? In any case your very welcome, helping other actually helps yourself as your hit more problems and also find out how others fix them. also you get exposed to new functions, Smart people learn from their mistakes, very smart people learn from other peoples mistakes Quote Link to comment https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967917 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.