Page 1 of 1

Limiting Records

Posted: Tue Mar 17, 2009 12:07 pm
by dmgt
This code limits records to 12 records per page. Can anyone tell me how to control the number of records per page?

I don't see anywhere where the limit is set to 12... Not sure what I am missing.

Thanks

Code: Select all

 
 
<?
class newsSql{
 
function getNews($perPage='0',$onPage='0',$where='')
{
 
global $DB,$AUTH;
 
$sqlstart = ($perPage * $onPage) - ($perPage);
$sqlstop= $perPage;
 
$limit = ($sqlstart == 0 && $sqlstop == 0 ) ? '' : " LIMIT ".$sqlstart.",".$sqlstop;
 
$sql="SELECT SQL_CALC_FOUND_ROWS  * from GTM_NEWS  ";
 
$sql .= ($where != "") ? $where : '';
$sql .=" ORDER by date_entered DESC " ;
 
$sql .=  $limit;
 
$res = $DB->run_query($sql);
 
//print_r($DB);
if($res && $res->num_rows > 0 )
{
//print_r($res);
$pgs = $DB->getTotalPages($perPage);
$res->total_num_items = $pgs['totalItems'];
$res->total_pages = $pgs['totalPages'];
return $res;
}
return false;
}
 
 
function getArticle($id)
{
 
    global $DB;
 
    if( ! is_numeric($id) ) return false;
 
   $res = $DB->run_query("SELECT * FROM GTM_NEWS WHERE news_id='".$id."'");
 
        if($res && $res->num_rows == 1)
        {
//print_r($res);
                return $res->row;
 
        }
        else
        {
                return false;
        }
 
 
 
}
 
}// end class
 
?>

Re: Limiting Records

Posted: Wed Mar 18, 2009 11:35 am
by susrisha

Code: Select all

 
$sql .=  $limit;
 
echo $sql; //add this statement and you will know... WHERE to limit it 
$res = $DB->run_query($sql);
 

Re: Limiting Records

Posted: Wed Mar 18, 2009 7:52 pm
by dmgt
Thanks- below is what i received from the echo... It doesn't explain to me where the value of 12 is set- I must be missing something pretty obvious...


SELECT SQL_CALC_FOUND_ROWS * from GTM_NEWS ORDER by date_entered DESC LIMIT 0,12

Re: Limiting Records

Posted: Wed Mar 18, 2009 8:54 pm
by Benjamin
It's set in the code calling the class...

Code: Select all

 
function getNews($perPage='0',$onPage='0',$where='')
 

Re: Limiting Records

Posted: Wed Mar 18, 2009 11:03 pm
by dmgt
That makes sense. But I can't figure out where it is getting the 12 per page?

Re: Limiting Records

Posted: Wed Mar 18, 2009 11:14 pm
by Benjamin
Where are you calling the function?

Re: Limiting Records

Posted: Thu Mar 19, 2009 9:43 am
by dmgt

Code: Select all

 
<?
require_once('news_sql.php');
require_once(PATH_MODS.'maps/maps_data.php');
 
class getnews extends news_sql {
 
    var $NEWSSQL = '';
    var $perPage = '3';
 
function getnews()
{
// nothing
}
 
 
 
function getNewsList($where='')
{
 
    global $REQ,$OUT,$FNS;
    
    $onPage = (isset($REQ->urlArray['page']) && is_numeric($REQ->urlArray['page'])) ? $REQ->urlArray['page'] : 1;
    $queryRes = $this->NEWSSQL->getNews($this->perPage,$onPage,$where);
    $output = array();
    if($queryRes && $queryRes->num_rows > 0 )
    {
        foreach($queryRes->result as $row)
        {
            $row['mids'] = explode(',',$row['news_mapids']);
            $output[] = $row;
        }   
                $OUT->templateVars['newsList'] = $output;
                $OUT->templateVars['queryTotal']  = $queryRes->total_num_items;
                $OUT->templateVars['Paging'] =$FNS->getPaging($queryRes->total_pages,$onPage,$this->perPage);
    }
    else
        {
                $OUT->templateVars['no_query_results'] = true;
        }
 
}
 
function getArticle($id)
{
$data = $this->NEWSSQL->getArticle($id);
return $data;
 
}
 
}// end class
?>