possibly more efficient record counting query, and fix limit case on queries that return less than limit

This commit is contained in:
Miles Lott 2003-10-19 08:06:52 +00:00
parent a6247a6191
commit c02c4f563e

View File

@ -491,31 +491,45 @@
$query = ereg_replace('"','',$query);
$sql = "SELECT * FROM $this->std_table WHERE (";
$sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE (";
reset($this->stock_contact_fields);
while(list($f,$x) = each($this->stock_contact_fields))
{
$sql .= " UPPER($f) LIKE UPPER('%$query%') OR ";
$sqlcount .= $sql;
}
$sql = substr($sql,0,-3) . ') ' . $fand . $filtermethod . $ordermethod;
$sqlcount = $sql;
unset($f); unset($x);
}
else
{
$sql = "SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere
. $filtermethod . ' ' . $ordermethod;
$sqlcount = "SELECT COUNT(id) FROM $this->std_table " . $fwhere
. $filtermethod . ' ' . $ordermethod;
}
if($DEBUG) { echo '<br>' . $sql; }
// $db2 = $this->db;
copyobj($this->db,$db2);
$this->db->query($sql,__LINE__,__FILE__);
/* Perhaps it is more efficient to count records for this query, which is all we need here */
$this->db->query($sqlcount,__LINE__,__FILE__);
unset($sqlcount);
$this->total_records = $this->db->num_rows();
if($start && $limit)
{
if($this->total_records <= $limit)
{
$this->db->query($sql,__LINE__,__FILE__);
}
else
{
$this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit);
}
}
elseif(!$limit)
{
$this->db->query($sql,__LINE__,__FILE__);
@ -536,7 +550,7 @@
$return_fields[$i]['cat_id'] = $this->db->f('cat_id');
$return_fields[$i]['last_mod'] = $this->db->f('last_mod');
if (gettype($stock_fieldnames) == 'array')
if(@is_array($stock_fieldnames))
{
while(list($f_name) = each($stock_fieldnames))
{