• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FROM is adding 1 to SQL..

#1
Hi,

I have a problem with FROM. I am trying a join two tables, but the FROM function is adding 1 number to SQL sentences.

My codes : 

PHP Code:
$company $ci->db->select('MUST.*, PERS.*')->from('musteriler as MUST')
                        ->
join('ilgili_kisiler AS PERS''PERS.musteri_id = MUST.id''inner')
                        ->
get_where(array('PERS.id' => $person_id)); 


Output:

Code:
SELECT `MUST`.*, `PERS`.* FROM (`musteriler` as `MUST`, 1) INNER JOIN `ilgili_kisiler` AS `PERS` ON `PERS`.`musteri_id` = `MUST`.`id`


You can see there is a 1 number in FROM ... 

How can I fix this ?
Reply

#2
@sDenizhan17,

The output was from CI (Codeigniter)? Is this MySQL?
Reply

#3
The first argument to get_where should be the name of the table. Fix that and see what happens.
Reply

#4
(06-28-2018, 04:22 PM)dave friend Wrote: The first argument to get_where should be the name of the table. Fix that and see what happens.

PERS is name of the table.
Reply

#5
(06-28-2018, 09:12 AM)php_rocs Wrote: @sDenizhan17,

The output was from CI (Codeigniter)?  Is this MySQL?

Output is from CI.
Reply

#6
@sDenizhan17,

I prefer to do my queries this way (documentation: https://codeigniter.com/user_guide/datab...y-bindings). Maybe it will work for you. I don't know why the one is appearing in your query?

$qry = "SELECT MUST.*, PERS.* FROM musteriler as MUST INNER JOIN ilgili_kisiler AS PERS ON PERS.musteri_id = MUST.id WHERE PERS.id = ?";

$val = [$person_id];

$company = $ci->db->query($qry,$val);
Reply

#7
(07-02-2018, 02:22 AM)sDenizhan17 Wrote:
(06-28-2018, 04:22 PM)dave friend Wrote: The first argument to get_where should be the name of the table. Fix that and see what happens.

PERS is name of the table.

Your code

PHP Code:
->get_where(array('PERS.id' => $person_id)); 

supplies only one argument. Try

PHP Code:
->get_where('PERS', array('PERS.id' => $person_id)); 

On further consideration, you could probably do this

PHP Code:
$company $ci->db
    
->select('*')
    ->
from('musteriler as MUST')
    ->
join('ilgili_kisiler AS PERS''PERS.musteri_id = MUST.id''inner')
   ->
where(array('PERS.id' => $person_id))
   ->
get(); 

I believe that select('*') in combination with the join statment will give you all fields from both tables.
Reply

#8
(07-02-2018, 12:41 PM)dave friend Wrote:
(07-02-2018, 02:22 AM)sDenizhan17 Wrote:
(06-28-2018, 04:22 PM)dave friend Wrote: The first argument to get_where should be the name of the table. Fix that and see what happens.

PERS is name of the table.

Your code

PHP Code:
->get_where(array('PERS.id' => $person_id)); 

supplies only one argument. Try

PHP Code:
->get_where('PERS', array('PERS.id' => $person_id)); 

On further consideration, you could probably do this

PHP Code:
$company $ci->db
    
->select('*')
 
   ->from('musteriler as MUST')
 
   ->join('ilgili_kisiler AS PERS''PERS.musteri_id = MUST.id''inner')
 
  ->where(array('PERS.id' => $person_id))
 
  ->get(); 

I believe that select('*') in combination with the join statment will give you all fields from both tables.

Thank you dave.. 

You right. I forgot write the first argument to get_where. When i write it fixed.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.