Friday, 9 August 2013

Php MySQL select from multiple tables

Php MySQL select from multiple tables

I know that there are several posts about this, but I can't get this to
work. I don't have any experience of MySQL "join" or "left", only simple
querys.
I've got 3 tables: categories, companies and catcomp
Categories
id | name | ... | ... |
1 | Foo
2 | Bar
Companies
id | name | ... | ...
1 | Company1
2 | Company2
Catcomp (To store multiple categories for one company)
company_id | category_id
1 | 1
1 | 2
2 | 2
I've only got this:
$result = mysql_query("SELECT * FROM categories");
while($row = mysql_fetch_array($result)) {
echo '<input type="checkbox" id="'.$row['id'].'" name="cat[]"
value="'.$row['id'].'">'.$row['name'].'<br>
}
This prints out all categories with checkboxes.. I want the boxes to be
checked for the current company.
This is giving me a headache! Any ideas?
Thanks!

No comments:

Post a Comment