-2

I have two table for category name and post. Now i need to show category name for each post like this :

$joinedcontent = Access::FETCH("SELECT * FROM " . CONTENT . 
" LEFT JOIN " . POST . "  ON category = id WHERE  id = ?", $row['id']);
$ccats= $joinedcontent[0]['name'];

In result i see this error:

Error: Column 'id' in where clause is ambiguous Statement: SELECT * FROM cms_content LEFT JOIN cms_posts ON type = id WHERE id = ? Arguments: Array ( [۰] => 30 )

how do fix this error?

Perspolis
  • 862
  • 3
  • 11
  • 28

2 Answers2

1

This is an ambiguity for the database that the "id" column specified in where clause, belongs to which table. CONTENT or POST? You have to specify the name of the table before the column name to identify it. For example:

$joinedcontent = Access::FETCH("SELECT * FROM " . CONTENT . 
" LEFT JOIN " . POST . "  ON category =  " . POST . ".id WHERE  " . POST . ".id = ?", $row['id']);
$ccats= $joinedcontent[0]['name'];
Ahmad
  • 5,551
  • 8
  • 41
  • 57
0

Might be same column available in other table. so please use table.column to avoid conflict column (ambigity)

pmr
  • 14
  • 1