Welcome Guest, Not a member yet? Register   Sign In
Query Problem
#1

[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 ?
#2

[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);
#3

[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 ?
#4

[eluser]jmadsen[/eluser]
try

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

but I find it to be unreliable at times
#5

[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)`
#6

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

[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.
#8

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

[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
#10

[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;





Theme © iAndrew 2016 - Forum software by © MyBB