简体   繁体   English

餐饮搜索/过滤应用程序的数据库表结构

[英]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. 我正在建立一个食品清单应用程序,使用PHP作为后端,使用mysql作为数据库。 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. 您可以使用多表搜索的JOIN代码,请参见下文。

 $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 . "%'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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