关系表:具有关系的第三个表
我正在构建一个 php 页面,当用户在表单字段中输入他/她的电话号码时,该页面将显示特定的横幅。
所以这是我的数据库逻辑:
表电话与字段:id、用户名和电话号码。 表横幅,其中包含以下字段:id、横幅的名称/标题和横幅(图像的路径)。 表与字段的关系:这里是电话号码应该与横幅相关的地方,也是我需要你帮助的地方:)
这是我的 php 页面的逻辑:
-form 获取电话号码 -我查询数据库 -我显示与表单中输入的电话号码相关的横幅。
下面是到目前为止创建表的代码..您将看到不知道如何前进。
感谢一百万
CREATE TABLE phones(
id_phone INT NOT NULL AUTO_INCREMENT,
nombre VARCHAR(30),
number INT (9),
PRIMARY KEY (id_phone)
) TYPE = INNODB;
CREATE TABLE banners (
id_banners INT NOT NULL AUTO_INCREMENT,
id_phone INT NOT NULL,
name VARCHAR(250),
banner VARCHAR(250),
PRIMARY KEY(id_phone),
INDEX (id_phone),
FOREIGN KEY (id_phone) REFERENCES clientes(id_phone)
) TYPE = INNODB;
I'm building a php page that will show an specific banner when the user enters his/her phone number in a form field.
So here's my logic for the database:
Table phones with fields: id, name of user and phone number.
Table banners with fields: id, banner's name/title and banner (path to the image).
Table relation with fields: here's where the phone number should be related to a banner and where I need your help :)
And here's my logic for the php page:
-form gets the phone number
-I query the data base
-I show the banner related to the phone number entered in the form.
Below is the code for the table creation so far .. as you'll see don't know how to advance.
Thanks a million
CREATE TABLE phones(
id_phone INT NOT NULL AUTO_INCREMENT,
nombre VARCHAR(30),
number INT (9),
PRIMARY KEY (id_phone)
) TYPE = INNODB;
CREATE TABLE banners (
id_banners INT NOT NULL AUTO_INCREMENT,
id_phone INT NOT NULL,
name VARCHAR(250),
banner VARCHAR(250),
PRIMARY KEY(id_phone),
INDEX (id_phone),
FOREIGN KEY (id_phone) REFERENCES clientes(id_phone)
) TYPE = INNODB;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的问题来看,似乎每个电话号码都只有一个与之关联的横幅。因此,删除
banners.id_banners
字段并添加phones.id_banners
然后选择数据,可以进行 JOIN:
From your question, it seems that each phone number has only one banner associated with it. Therefore, delete the
banners.id_banners
field and add aphones.id_banners
Then to select the data, you can do a JOIN:
首先,问题是什么?
在这一步我要提到的是,这些实体之间的关系是否是一对一的?如果是这样,您最好将所有这些数据放入一张表中。
++
查询将是:
First of all what's the question?
What can I mention at this step is, does the relation between this entities is one to one? If so, you'd better put all this data into one single table.
++
and the query would be: