I get the number of rows on a constrained record by using
$table1="tab1";
$table2="tab2";
$query=sprintf("SELECT '%s'.* FROM '%s' JOIN '%s' ON ('%s'.id='%s'.id)",
$table1,
$table1,
$table2,
$table1,
$table2);
$query=$this->db->query($query);
return $query->num_rows();
and I come up with the following error, I am using latest XAMPP with mysql version 5.1
Error Number: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘.* FROM ‘tab1’ JOIN ‘tab2’ ON
(‘tab1′.userid=’tab2′.userid)’ at line 1SELECT ‘tab1’.* FROM ‘tab1’ JOIN ‘tab2’ ON
(‘tab1′.userid=’tab2’.userid)Filename: A:\CodeIgniter_2.1.0\system\database\DB_driver.php
Line Number: 330
UPDATE
$query=sprintf("SELECT `%s`.* FROM `%s` JOIN `%s` ON (`%s`.id=`%s`.id) LIMTI `%d`, `%d`",
$table1,
$table1,
$table2,
$table1,
$table2,
$num1,
$num2);
the error is
Error Number: 1327
Undeclared variable: 5
SELECT
tab1.* FROMtab1JOINtab2ON
(tab1.userid=tab2.userid) LIMIT5,0Filename: A:\CodeIgniter_2.1.0\system\database\DB_driver.php
Line Number: 330
Try this code.
I think your second query should be like this.