This topic is locked
[SOLVED]

 explode on custom view

12/9/2011 6:34:01 PM
PHPRunner General questions
S
stiven author

hello, on a custom view of a field i'm trying to change the date format but i get error "Undefined Offset 1" here is the code i have no clue why i'm getting that error


global $conn;

$sql = "SELECT `viewing_date`, `start_time`, `end_time` FROM `viewing` WHERE `case_no` = '".$case."'";

$rs = db_query($sql,$conn);

$row = db_fetch_array($rs);
$rawdate = explode('-', $row['viewing_date']);

$fdate = $rawdate[1]."/".$rawdate[2]."/".$rawdate[0];/// this is the error line
$msg = 'Date: '.$fdate.' Start Time: '.$row['start_time'].' End Time: '.$row['end_time'].' Place: '.$row['chapel_name'];
$viewinginfo = $msg;


Thanks for your help

C
cgphp 12/10/2011

Try to debug your code. Echo the $row['viewing_date'] value before calling explode():

echo $row['viewing_date'];

exit();



Is it a valid date format ?
Is the field case_no an INT type ? If so, your query should be:

$sql = "SELECT `viewing_date`, `start_time`, `end_time` FROM `viewing` WHERE `case_no` = ".$case;
S
stiven author 12/10/2011

ok I found the problem. the first three records on the list didn't exist on the table viewing and that's why it was throwing that error.
Thanks for your help



Try to debug your code. Echo the $row['viewing_date'] value before calling explode():

echo $row['viewing_date'];

exit();



Is it a valid date format ?
Is the field case_no an INT type ? If so, your query should be:

$sql = "SELECT `viewing_date`, `start_time`, `end_time` FROM `viewing` WHERE `case_no` = ".$case;