why this sql not working?
Posted
by user295189
on Stack Overflow
See other posts from Stack Overflow
or by user295189
Published on 2010-04-20T18:41:51Z
Indexed on
2010/04/20
18:43 UTC
Read the original article
Hit count: 479
I have a query
public static function TestQuery(
$start=0, $limit=0){
$sql = " SELECT count(*) AS total FROM db.table1 JOIN db.table2 ON table1.fieldID = {$fieldID}
AND table2.assigned = 'N'";
$qry = new SQLQuery; $qry->query($sql); if($row = $qry->fetchRow()){ $total = intval($row->total); }
return $total;
} which works fine but when I add the limit as below, then it doesnt work and gives me errors
public static function TestQuery(
$start=0, $limit=0){
$sql = " SELECT count(*) AS total FROM db.table1 JOIN db.table2 ON table1.fieldID = {$fieldID}
AND table2.assigned = 'N'";
//this fails
if($recordlimit > 0) $sql .= "LIMIT {$startRecord}, {$recordLimit} ";
//
$qry = new SQLQuery;
$qry->query($sql);
if($row = $qry->fetchRow()){
$total = intval($row->total);
}
return $total;
}
Any help will be appreciated
© Stack Overflow or respective owner