I have three tables:
Shop
Shop_id City_id Address
1 1 Address 1
2 1 Address 2
3 2 Address 3
4 2 Address 4
5 1 Address 5
6 1 Address 6
City
City_id Name
1 Vilnius
2 Kaunas
Places
Place_id Shop_id Book_id
1 3 1
2 2 1
3 3 2
4 4 3
5 3 3
In Places
table I save shops where you can buy specific book.
Also I have checkboxes form:
$result = mysql_query("SELECT places.place_id, places.book_id, places.shop_id,
shop.shop_id, shop.city_id,shop.address,city.city_id,city.name
FROM shop INNER JOIN places ON places.shop_id=shop.shop_id
INNER JOIN city ON shop.city_id=city.city_id") or die(mysql_error());
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result2)) {
echo '<tr>
<td><input type="checkbox"'; if ($row['book_id']==$id2){echo 'checked';}echo' name="identifer[]" value="'.$row['shop_id'].'" /> <br /></td>
<td>'.ucfirst($row['Name']).','.$row['Address'].' </td>
</tr>
I'm trying to create table with all available shops with checbox checked value if Book_id
equal to $id2
.
To be more clear here is the screenshot, it shows what I get from my code:
Obviously, it basically write down all shops from Places
table. I'm trying to change my SQL code, but I can't get it right, so I need help.
all shops
orall places
? Multiple places per shop! You text tells a different story from your query.