![]() |
FROM is adding 1 to SQL.. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19) +--- Thread: FROM is adding 1 to SQL.. (/showthread.php?tid=71036) |
FROM is adding 1 to SQL.. - sDenizhan17 - 06-28-2018 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') 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 ? RE: FROM is adding 1 to SQL.. - php_rocs - 06-28-2018 @sDenizhan17, The output was from CI (Codeigniter)? Is this MySQL? RE: FROM is adding 1 to SQL.. - dave friend - 06-28-2018 The first argument to get_where should be the name of the table. Fix that and see what happens. RE: FROM is adding 1 to SQL.. - sDenizhan17 - 07-02-2018 (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. RE: FROM is adding 1 to SQL.. - sDenizhan17 - 07-02-2018 (06-28-2018, 09:12 AM)php_rocs Wrote: @sDenizhan17, Output is from CI. RE: FROM is adding 1 to SQL.. - php_rocs - 07-02-2018 @sDenizhan17, I prefer to do my queries this way (documentation: https://codeigniter.com/user_guide/database/queries.html#query-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); RE: FROM is adding 1 to SQL.. - dave friend - 07-02-2018 (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. 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 I believe that select('*') in combination with the join statment will give you all fields from both tables. RE: FROM is adding 1 to SQL.. - sDenizhan17 - 07-03-2018 (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. Thank you dave.. You right. I forgot write the first argument to get_where. When i write it fixed. |