こんにちは、私は codeigniter アクティブ レコードを使用しています。タルベ ジョインを作成したいと考えています。
これは私の質問です
$table = $this->mastables ['table1'];
$table1 = $this->mastables ['table2'];
$this->db->select ( 'a.RelationshipCategoryName,a.RelationshipCategoryID,COUNT( b.ShopRelationshipID ) AS count' );
$this->db->from ( $table . " as a" );
$this->db->join ( $table1 . " as b", "(( a.RelationshipCategoryID=b.RecieverRelationshipCategory AND b.3rdPartyID=" .$shop_id. " ) OR ( a.RelationshipCategoryID=b.SenderRelationshipCategory AND b.ShopID=" .$shop_id. " )) AND b.IsDelete!=1", 'left' );
$this->db->where ( 'a.ShopID', $shop_id );
$this->db->where ( 'a.IsActive', 1 );
if ($limit != NULL) {
$this->db->limit ( $limit, $offset );
}
if ($oderby != NULL && $oder != NULL) {
$this->db->order_by ( $oderby, $oder );
}
$this->db->group_by ( 'a.RelationshipCategoryID' );
$query = $this->db->get ();
if ($query->num_rows () > 0) {
return $query->result_array ();
} else {
return FALSE;
}
エラーは
A Database Error Occurred
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 ') OR ( a.RelationshipCategoryID=b.SenderRelationshipCategory AND b.ShopID=11 )) ' at line 3
SELECT `a`.`RelationshipCategoryName`, `a`.`RelationshipCategoryID`, COUNT( b.ShopRelationshipID ) AS count FROM (`mas_shop_relationship_category` as a) LEFT JOIN `mas_shop_relationship` as b ON `a`.`RelationshipCategoryID`=`b`.`RecieverRelationshipCategory` AND b.3rdPartyID=11 ) OR ( a.RelationshipCategoryID=b.SenderRelationshipCategory AND b.ShopID=11 )) AND b.IsDelete!=1 WHERE `a`.`ShopID` = '11' AND `a`.`IsActive` = 1 GROUP BY `a`.`RelationshipCategoryID` ORDER BY `a`.`RelationshipCategoryName` asc LIMIT 5
Filename: C:\xampp\htdocs\elephanti2\system\database\DB_driver.php
Line Number: 330
エラーはこの行から来ています
$this->db->join ( $table1 . " as b", "(( a.RelationshipCategoryID=b.RecieverRelationshipCategory AND b.3rdPartyID=" .$shop_id. " ) OR ( a.RelationshipCategoryID=b.SenderRelationshipCategory AND b.ShopID=" .$shop_id. " )) AND b.IsDelete!=1", 'left' );
コードのこの部分をコードに正しく追加する方法
(( a.RelationshipCategoryID=b.RecieverRelationshipCategory AND b.3rdPartyID=" .$shop_id. " ) OR ( a.RelationshipCategoryID=b.SenderRelationshipCategory AND b.ShopID=" .$shop_id. " ))