0
votes

i have a query as follows and it gives me a error my query in model is

$query = $this->db->select('SELECT AV.Ad_ID, AV.Title, AV.Price, LT1.Listing')
              ->from('ad_vehicle')
              ->join('ref_listing_type', 'ad_vehicle.Listing_Type_ID = ref_listing_type.Listing_ID', 'inner')
              ->where('ad_vehicle.Created_By', 1)
              ->get();
var_dump($query);
return $query->result_array();

and my error is

A Database Error Occurred

Error Number: 1064

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 '.Ad_ID, AV.Title, AV.Price, LT1.Listing FROM (ad_vehicle) INNER JO' at line 1

SELECT `SELECT` AV.Ad_ID, `AV`.`Title`, `AV`.`Price`, `LT1`.`Listing`
FROM (`ad_vehicle`) 
INNER JOIN `ref_listing_type` ON `ad_vehicle`.`Listing_Type_ID` = `ref_listing_type`.`Listing_ID` 
WHERE `ad_vehicle`.`Created_By` = 1

Filename: C:\wamp\www\DoolalyJobsBackup\system\database\DB_driver.php

Line Number: 330

1

1 Answers

0
votes

Change your select() to

 $query = $this->db->select('AV.Ad_ID, AV.Title, AV.Price, LT1.Listing')

Using active record's select() will automatically adds a SELECT keyword you don't need to add again in your query,Also in your query you have used short aliases for the tables but you haven't assign them

$this->db->select('AV.Ad_ID, AV.Title, AV.Price, LT1.Listing')
              ->from('ad_vehicle AV')
              ->join('ref_listing_type LT1', 'AV.Listing_Type_ID = LT1.Listing_ID', 'inner')
              ->where('AV.Created_By', 1)
              ->get();