0

Received an error message

Notice: Undefined offset: 1 ... on line 83

and not sure what it means.

The snippet of code with the function where the message comes from is

$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
    $time = $row['vluchttijd'];
    function timeInWords($time) {
        list($hours, $minutes) = explode(':', $time);
        return (int)$hours .  " hrs " . (int)$minutes . " min";**
   }

Line 83 is:

list($hours, $minutes) = explode(':', $time);

What am I missing here?

EDITED: Now I get no error, but the query should have 3 results and now I only get 1.

Also I had to add one more line, so now the code looks like:

$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
    $time = $row['vluchttijd'];
    if (!function_exists('timeInWords')) {
    function timeInWords($time) {
        list($hours, $minutes) = explode(':', $time);
        return (int)$hours .  " hrs " . (int)$minutes . " min";
   }    $result = mysql_query($sql);

{
  • 4
    `var_dump( explode(':', $time) );` gives you an array of length >=2? – kero May 09 '14 at 22:52
  • Expanding on @kingkero, I'm assuming your time does not contain `:` so there isn't a second value to be assigned to `$minutes`. – Sam May 09 '14 at 23:00
  • The field vluchttijd is a time database field, ie: 12:30. The function is to convert the 12:30 into 12 hours 30 minutes. it works perfectly on a different page, but it's not exactly the same setup - a single page with a html template. This one needs to be able to show multiple "records" within a "template". –  May 09 '14 at 23:19
  • @kingkero I had to add back if (!function_exists('timeInWords')) { and then it worked to a point. Now instead of displaying all 3 records for this one query, it only shows 1. [oh, and there should have been an = in line 1 –  May 09 '14 at 23:45

0 Answers0