I am using a FFDB database (Flat File Database).
This script works but it only shows first record (#1), if I delete the 1st record I get a blank page. I want to call all records and find 1 (one) that matches the criteria(s) independent of its record (key) number.
I want to load this file when the HTML page loads (with or w/o iframe):
<?php
/*!
* @function getall
* @abstract retrieves all records in the database, each record in an array
* element.
* @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($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();
return $result;
}
function returnRec($item){
if($item)
return true;
}
$db = new FFDB();
if (!$db->open("foo"))
{
$schema = array(
array("key", FFDB_INT, "key"),
array("status", FFDB_STRING),
array("vinc", FFDB_STRING),
array("month", FFDB_STRING),
array("day", FFDB_INT),
array("year", FFDB_INT)
);
// Try and create it...
if (!$db->create("foo", $schema))
{
echo "Error creating database\n";
return;
}
}
$result = $db->getall();
foreach($result as $item){
show_record($item);
break;
}
function show_record($record){
$number = $record["key"];
$Rvinc = $record["vinc"];
$Rstatus = $record["status"];
$Rday = $record["day"];
$Rmonth = $record["month"];
$Ryear = $record["year"];
$tday = getdate();
$current_year = $tday['year'];
$current_month = $tday['month'];
if (($status == ON) && ($vinc == R1) && ($month >= $current_month) && ($year == $current_year)){
echo "myrecord $vinc $status $day $month $year";
}
?>
I may need to improve this is order to get the result, but I tried and it doesn't work, so here is the basic for help:
function returnRec($item){
if($item)
return true;
}
or perhaps improvement here:
$result = $db->getall();
foreach($result as $item){
show_record($item);
break;
}
Any help PLEASE?!
Thanks