我如何使用PHP,mysql解决这个问题。
我在数据库中有三个表。第一个表有主键indno(自动增量),第二个表有indno ad外键和sn作为主键(AI),第三个表有sn作为外键,id作为主键(AI)。
我在html中创建了一个表单,并使用php,sql从用户那里插入值。我想编写查询以将之前的结果提取到表单中,以便登录的用户可以更改并更新数据,如果他/她使用的话。
我尝试了什么:
查询中有错误。
i used- SELECT * FROM sailform6,sailform7,sailform8其中indno = $ indno;
和形式我使用的值=
I have three tables in a database. First table has primary key indno(auto increment), second table has indno ad foreign key and sn as a primary key(AI), third table has sn as foreign key and id as primary key(AI).
I made a form in html and and inserted values in that form from user using php,sql. I want to write query to fetch previous result into the form so that the logged in user may change and update the data if he/she whises to.
What I have tried:
There is an error in query.
i used- SELECT * FROM sailform6,sailform7,sailform8 where indno=$indno";
and in the form i used value= ""
indno;
和我使用的形式value =
indno";
and in the form i used value= ""
你需要使用JOINS。
SELECT *
来自sailform6 s6
LEFT JOIN sailform7 s7 ON s6.indno = s7.indno
LEFT JOIN sailform8 s8 ON s6.indno = s8.sn
You need to use JOINS.
SELECT *
FROM sailform6 s6
LEFT JOIN sailform7 s7 ON s6.indno = s7.indno
LEFT JOIN sailform8 s8 ON s6.indno = s8.sn
首先,了解 SQL连接的可视化表示 [ ^ ]
后跟多个联接如何工作 [ ^ ]
First, learn about Visual Representation of SQL Joins[^]
followed by How Multiple Joins Work[^]