我使用的平面文件數據庫,而不是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()
當文件來平爲單個文件,沒有關於它有多少記錄,記錄= 1或記錄= 100在這一點上是相同的。
Break;不起作用,因爲所有記錄都是單一記錄 - 因此沒有什麼可以打破的。
我想要做的是分裂/爆炸的記錄,盡數,並根據我的if語句後:
if $i == 0 echo "content1";
if $i == 1 echo "content2";
if $i > 1 echo "content 3";
我來到這裏舉行了近3天......用盡了所有的解決方案。
HELP高興認識 感謝
你有沒有的平面文件是如何佈局的例子嗎? – vascowhite
有沒有理由讓你這麼做? (文件與數據庫) – 2011-07-15 02:12:41