PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 12, 2022

[FIXED] LEFT JOIN in Codeigniter shows syntax error

 February 12, 2022     codeigniter, left-join, mysql     No comments   

Issue

I want to select a table which holds all the issues a specific project id has. For that I am planning to do a LEFT JOIN and get the projects_id in Projects table to the column 'issues_projects_id' in issues table. Isn't it a JOIN that has to be used here?

    // $this->db->join('issues', 'issues.issues_projects_id = projects.projects_id', 'left');
   // $query1 = $this->db->get();
   $squery="SELECT * FROM projects LEFT JOIN issues ON issues.issues_projects_id=projects.projects_id";
    $query1= $this->db->query($squery);
    $query= $this->db->query($squery);
    return $query->result();
    return $query1->result();

The above code shows below error & displays no output.

A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LEFT JOIN `issues` ON `issues`.`issues_projects_id` = `projects`.`projects_id`' at line 2

SELECT * LEFT JOIN `issues` ON `issues`.`issues_projects_id` = `projects`.`projects_id`

Filename: C:/wamp64/www/projects/issue_tracker/system/database/DB_driver.php

Line Number: 691

Projects Table

projects_id projects_name
1 abc
2 xyz

Issues Table

issues_id issues_description issues_projects_id
1 gfj 1
2 fghgj 1

Solution

you are missing from statement:

SELECT * 
FROM `projects` --< here 
LEFT JOIN `issues` 
  ON `issues`.`issues_projects_id` = `projects`.`projects_id`
WHERE projects_id = ?


Answered By - eshirvana
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing