I am using flat file db, not mysql so I can't use $limit

I need to limit the number of records to 1, if more than 1 then echos something else:

$result = $db->getall(month);
foreach($result as $item)
     show_record($item);
}

I tried to use 'break' but it comes back 0(zero) records.

I tried using $i = 0...but it returned all or nothing

Any ideas?
Thanks

$result=$db-> getall(month);
show_record(0);

?

"$result=$db-> getall(month);show_record(0);"

almostbob, I already tried this before, but it only returns the lowest record-key, and not the record I am calling with an if statement

any other ideas, tks

:( a little more of the active code please,

@almostbob, here it goes:

function getall()

/*!
    * @function getall
    * @abstract retrieves all records in the database, each record in an array
        * element.
    * @param orderby  order the results.  Set to the field name to order by
    * (as a string). If left unset, sorting is not done and it is a lot faster.
    * If prefixed by "!", results will be ordered in reverse order.  
    * If orderby is an array, the 1st element refers to the field to order by,
    * and the 2nd, a function that will take two take two parameters A and B 
        * - two fields from two records - used to do the ordering.  It is expected 
    * that the function would return -ve if A < B and +ve if A > B, or zero 
    * if A == B (to order in ascending order).
    * @param includeindex  if true, an extra field called 'FFDB_IFIELD' will
    * be added to each record returned.  It will contain an int that specifies
    * the original position in the database (zero based) that the record is 
    * positioned.  It might be useful when an orderby is used, and an future 
    * operation on a record is required, given it's index in the table.
    * @result all database records as an array
    */
   function getall($orderby = NULL, $includeindex = false)
   {
      if (!$this->isopen)
      {
         user_error("Database not open.", E_USER_ERROR);
         return false;
      }

      // If there are no records, return
      if ($this->records == 0)
         return array();

      if (!$this->lock_read())
         return false;

      // Read the index
      $index = $this->read_index();

      // Read each record and add it to an array
      $rcount = 0;
      foreach($index as $offset)
      {
         // Read the record
         list($record, $rsize) = $this->read_record($this->data_fp, $offset);

         // Add the index field if required
         if ($includeindex)
            $record[FFDB_IFIELD] = $rcount++;

         // Add it to the result
         $result[] = $record;
      }

      $this->unlock();

      // Re-order as required
      if ($orderby !== NULL)
         return $this->order_by($result, $orderby);
      else
         return $result;
   }

Flat file db files request

$result = $db->getall(lmonth);
foreach($result as $item)
     show_record($item);
}

if condition - function show_record()

function show_record($record){
      $month = $record["lmonth"];
      $status = $record["lstatus"];
      $year = $record["lyear"];
   }
if (($status == ON) && ($month >= $current_month) && ($year >= $current_year)){
 echo "foo";
 }

thanks for the help!

try this

$result = $db->getall(lmonth);
$i=0;
foreach($result as $item)
{
    if($i<1)
    {
        show_record($item);
        exit;
    }
    $i++;
}

@karthik, I tried and the result is none...tks

SOLUTION

Print_r did the trick, and I was using echo:

print_r (show_record($row));

Here is the final code after tweaking it a little:

$result = $db->getall(lp_month,lp_year);
$i = 0;
foreach ($result as $row){
       print_r (show_record($row));
    if ($i >= 1) 
     break;
$i++;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.