CodeIgniter Forums
Query Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Query Problem (/showthread.php?tid=52800)

Pages: 1 2


Query Problem - El Forum - 06-27-2012

[eluser]tolgay[/eluser]
Hi

I am using this code
Code:
$this->db->select("*");
$this->db->from('arkadaslar');
$this->db->join('uyeler',"uyeler.id=(arkadaslar.uid+arkadaslar.fid)-2");
$this->db->get();

This is returning error

Quote: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 '' at line 3

SELECT *, `arkadaslar`.`uid` as i1, `arkadaslar`.`fid` as i2 FROM (`arkadaslar`) JOIN `uyeler` ON `uyeler`.`id`=(`i1+i2)`

But if I use this code

Code:
SELECT *FROM `arkadaslar` join uyeler on uyeler.id=(arkadaslar.uid+arkadaslar.fid)-2

This is working.Problem is the nails.How can I resolve this ?


Query Problem - El Forum - 06-27-2012

[eluser]jmadsen[/eluser]
you the problem with the protecting ` , i think?

Code:
(`i1+i2)`


I find ActiveRecord to be a bit tricky when trying to work with more complicated queries. I would recommend just using:


Code:
$sql = "SELECT *FROM `arkadaslar` join uyeler on uyeler.id=(arkadaslar.uid+arkadaslar.fid)-2";
$query = $this->db->query($sql);



Query Problem - El Forum - 06-27-2012

[eluser]tolgay[/eluser]
[quote author="jmadsen" date="1340789447"]you the problem with the protecting ` , i think?

Code:
(`i1+i2)`


I find ActiveRecord to be a bit tricky when trying to work with more complicated queries. I would recommend just using:


Code:
$sql = "SELECT *FROM `arkadaslar` join uyeler on uyeler.id=(arkadaslar.uid+arkadaslar.fid)-2";
$query = $this->db->query($sql);
[/quote]

I am not want use query function.Is there another way ?


Query Problem - El Forum - 06-27-2012

[eluser]jmadsen[/eluser]
try

Code:
$this->db->select("*", FALSE );

but I find it to be unreliable at times


Query Problem - El Forum - 06-27-2012

[eluser]tolgay[/eluser]
[quote author="jmadsen" date="1340793814"]try

Code:
$this->db->select("*", FALSE );

but I find it to be unreliable at times[/quote]

I used this

Code:
$this->db->select("*",false);
$this->db->from('arkadaslar');
$this->db->join('uyeler','uyeler.id=(arkadaslar.uid+arkadaslar.fid)-1)');
$this->db->get();

But it didn't work.

Quote: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 '' at line 3

SELECT * FROM (`arkadaslar`) JOIN `uyeler` ON `uyeler`.`id`=(`arkadaslar`.`uid+arkadaslar`.`fid)-1)`



Query Problem - El Forum - 06-27-2012

[eluser]InsiteFX[/eluser]
Did you count your opening and closing () ?
Code:
$this->db->join('uyeler','uyeler.id=(arkadaslar.uid+arkadaslar.fid)-1)');



Query Problem - El Forum - 06-27-2012

[eluser]tolgay[/eluser]
[quote author="InsiteFX" date="1340806904"]Did you count your opening and closing () ?
Code:
$this->db->join('uyeler','uyeler.id=(arkadaslar.uid+arkadaslar.fid)-1)');
[/quote]

I tried this but didn't work.


Query Problem - El Forum - 06-27-2012

[eluser]InsiteFX[/eluser]
Code:
$this->db->join('uyeler','uyeler.id=(arkadaslar.uid+arkadaslar.fid)-1');



Query Problem - El Forum - 06-27-2012

[eluser]tolgay[/eluser]
[quote author="InsiteFX" date="1340813407"]
Code:
$this->db->join('uyeler','uyeler.id=(arkadaslar.uid+arkadaslar.fid)-1');
[/quote]

Didn't Work Sad


Query Problem - El Forum - 06-27-2012

[eluser]InsiteFX[/eluser]
Code:
$this->db->join('uyeler','uyeler.id = arkadaslar.uid + arkadaslar.fid-1', 'left');

After the query add this and it will show you what is going on.
Code:
echo $this->db->last_query();
exit;