Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967789
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967790
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967803
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967809
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967817
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967823
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967839
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967847
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967914
Share on other sites

I was trying to tell you thank you Mat Techie

 

Who's Mat ? :shrug:

 

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

Link to comment
https://forums.phpfreaks.com/topic/183353-umdefined-offset/#findComment-967917
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.