Page 1 of 1

sort() expects parameter 1 to be array, null given

Posted: Thu Jun 19, 2003 12:38 am
by STHayden
sort() expects parameter 1 to be array, null given
Variable passed to each() is not an array or object

I can't figure out what it is talking about since both have an array in them!

Code: Select all

Function getEvent ($theyear, $themonth, $theday)
{
$data_file = "../data/cd.dat";
    if(file_exists($data_file))
       {
       $data_lines = file($data_file);
       } 
     $Now = date(Ymd);
     sort($data_lines);         //it's angry here

     $ts =  mktime(0,0,0,substr($ts,4,2),substr($ts,6,2),substr($ts,0,4));
     while (list($Index, $Data) = each($data_lines))                       //And angry here as well
     {
      list($Date, $Type, $Title, $Time, $Location, $Price, $Description) = explode("|", $Data);
      
      if (($Date) && (substr($ts,0,4) == $theyear) && (substr($ts,4,2) == $themonth) && (substr($ts,6,2) == $theday))
      {
        if ($Title != "")
          {
          return "<br>$Title";
          }
      }
     }

Posted: Thu Jun 19, 2003 12:41 am
by ayron
maybe the file didn't exist?

Posted: Thu Jun 19, 2003 12:43 am
by STHayden
no it's definetly there.

I acualy use this same code in a different file and it works just fine


\/ this works.

Code: Select all

<?php
    $data_file = "../data/cd.dat";
    if(file_exists($data_file))
       {
       $data_lines = file($data_file);
       } 
     $Now = date(Ymd); 
     sort($data_lines);                                 //HERE
     function ts8totime ($ts) {return mktime(0,0,0,substr($ts,4,2),substr($ts,6,2),substr($ts,0,4));}
     while (list($Index, $Data) = each($data_lines))           //HERE
     {
      list($Date, $Type, $Title, $Time, $Location, $Price, $Description) = explode("|", $Data);
      if ($Type == "CUB")
      {
        if (($Date) && ($Date != $LastDate))
          echo "    <BR><FONT SIZE="+1"><DIV CLASS="date">" . date("l, F j, Y",ts8totime($Date)) . "</DIV></FONT>\r\n";
        if ($Title != "")
          {
          echo "    <FONT SIZE="+1"><SPAN CLASS="event-title">$Title</SPAN></FONT>\r\n";
          echo "    <FONT SIZE="-1"><SPAN CLASS="event-data">($Time, $Location, $Price)</SPAN></FONT><BR>\r\n";
          echo "    <SPAN CLASS="event-description">$Description</SPAN><BR>\r\n";
          }
        $LastDate = $Date;
        }
      } 
     ?>

Posted: Thu Jun 19, 2003 12:52 am
by ayron
have you checked the paths are correct? the logic of the code you're showing suggests that the file hasn't been read - try an echo inside the if statement to see if it has been opened

Posted: Thu Jun 19, 2003 1:06 am
by STHayden
your right. thanks for the help

Posted: Thu Jun 19, 2003 9:42 am
by hedge
I usually put a line just before the file read that forces the var to be an array, in your case

Code: Select all

...   
    $data_file = "../data/cd.dat"; 
    $data_lines = array();
    if(file_exists($data_file)) &#123; 
      $data_lines = file($data_file); 
    &#125; 
    $Now = date(Ymd); 
    sort($data_lines);
...