Я использую плоский файл базы данных, а не mysql, поэтому я не могу использовать $limit
Функция getbyfieldsw()
/*!
* @function getbyfieldsw
* @abstract retrieves records in the database whose field matches the
* given regular expression.
* @param fieldname the field which to do matching on
* @param regex the regular expression to match a field on.
* Note: you should include the delimiters ("/php/i" for example).
* @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 matching records in an array, or false on failure
*/
function getbyfieldsw($fieldname, $orderby = NULL, $includeindex = false) {
if (!$this->isopen)
{
user_error("Database not open.", E_USER_ERROR);
return false;
}
// Check the field name
if (!$this->key_exists_array($fieldname, $this->fields))
{
user_error(
"Invalid field name for getbyfield: $fieldname",
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);
// See if the record matches the regular expression
// Add the index field if required
if ($includeindex)
$record[FFDB_INDEX_RECORDS_OFFSET] = $rcount;
$result[] = $record;
++$rcount;
}
$this->unlock();
// Re-order as required
if ($orderby !== NULL)
return $this->order_by($result, $orderby);
else
return $result;
}
Функция 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";
}
Запись звонков - вот в чем проблема - это работает, кроме перерыва; - Мне нужно разобрать плоский файл, чтобы прочитать каждую запись в отдельности, а затем добавить к foreach ():
$result = $db->getbyfieldsw(lp_month);
$i = 0;
foreach ($result as $item){
show_record($item);
if ($i >= 2)
break;
}
Так как это плоский файл, при вызове функции getbyfieldsw()
файл получается плоским как один файл, независимо от того, сколько на нем записей, records = 1 или records = 100 в этот момент одинаковы.
Перерыв; не работает, потому что все записи идут как одна запись - поэтому ломать нечего.
То, что я хочу сделать, это разделить / разбить записи, посчитать их и основываясь на моем сообщении с утверждением if:
if $i == 0 echo "content1";
if $i == 1 echo "content2";
if $i > 1 echo "content 3";
Меня продержали здесь последние 3 дня ... исчерпали все решения.
ПОМОГИТЕ рад, ценится
Спасибо