简体   繁体   中英

Database table structure for a food and restaurant searching/filtering application

I am building an food listing application using PHP as backend and mysql as database. I have created three tables for searching. Below are the tables:

ADD RESTAURANT
id (AI primary)
res_id
name
description


FOOD CATEGORY (eg chinese, indian)
id (primary AI)
cat_id
res_id
category_name

FOOD SUB CATEGORY (eg noodles, chilly chicken )
id (PRIMARY AI)
cat_id
sub_id
name
price

How do I link these three tables such as when somebody searches for a specific food item it displays the shop from the first table, if searched by category then it displays the shop name also if searched by sub category name then also displays the shop name. Any kind of help would be appreciated.

you can use for multiple table search JOIN code see below.

 $query = "SELECT rest.name FROM RESTAURANT as rest INNER JOIN CATEGORY as cat ON cat.res_id = rest.res_id"
                . " INNER JOIN SUB_CATEGORY as sub_cat ON sub_cat.cat_id = cat.cat_id"
                . " where rest.name like '" . $search . "%' OR cat.category_name like '" . $search . "%' OR sub_cat.name like '" . $search . "%'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM