Page 1 of 1

INER JOIN first time writing

Posted: Tue Jun 14, 2011 11:12 am
by hostingebc
I write first time INER JOIN and i have error

Unknown column 'posts.id' in 'field list'


this is the query
[syntax=php]<?php
$query = "SELECT posts.id AS post_id, categories.id AS category_id,
title, contents, date_posted, categories.name
FROM posts
INER JOIN categories ON categories.id = posts.cat_id";
mysql_query($query)or die(mysql_error());

?>[/syntax]
and,
in my DB structure i have 2 tables:
1. categories - id, name,
2. postos - id, cat_id, title, contents, date_posted

wer is the problem?

thanks

Re: INER JOIN first time writing

Posted: Tue Jun 14, 2011 11:16 am
by jacek
are you sure the posts table has the column id, and not ID or something else.

Re: INER JOIN first time writing

Posted: Tue Jun 14, 2011 11:19 am
by hostingebc
Copy/paste header from php my admin
posts:
id cat_id title contents date_posted

categories:
id name

Re: INER JOIN first time writing

Posted: Tue Jun 14, 2011 12:14 pm
by hostingebc
hostingebc wrote:in my DB structure i have 2 tables:
1. categories - id, name,
2. postos - id, cat_id, title, contents, date_posted

wer is the problem?

thanks


UPDATE for secon table name

2. posts: id, cat_id, title, contents, date_posted

Re: INER JOIN first time writing

Posted: Tue Jun 14, 2011 1:22 pm
by jacek
hmm it does seem that you have a column called that.

you could try quoting the table and column names with backticks `

Re: INER JOIN first time writing

Posted: Tue Jun 14, 2011 3:23 pm
by Tino
Your table is postos, but you specify you're selecting from the posts table.

That's your problem ;)