php 的多表查询 怎么做??

我想做 有三张表的查询 每张表里的有两个一样的字段 这个该怎么做 具体点 最好 有个例子
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="textfield" id="textfield" />
</label>
<label></label>
<input type="submit" name="button" id="button" value="查询" />
</form>
</body>
</html>
在 text里 输入要查询的内容 那样的 该怎么做 最好连静态一起 写出来 新手 呵呵

很简单啊,可以选择JION关键字。
比如 <?php
session_start();
include "conn/conn.php";
$s_sqlstr="select * from xs inner jion xs_kc on xs.xh=xs_kc.xh" order by xh Desc";
$s_rst = $conn->execute($s_sqlstr);
?>
这就实现了两个表的查询,你也可以加别名,这样更方便书写追问



在 text里 输入要查询的内容 那样的 该怎么做 新手 写详细点 谢谢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-07
a b c 三张表 相同的字段假设是a. a1 a. a2 、b.b1 b.b2 和 c.c1 c.c2
SELECT * FROM a LEFT JOIN b ON a.a1=b.b1 AND a.a2=b.b2 LEFT JOIN c ON a.a1=c.c1 AND a.a2=c.c2 WHERE 1; left join right join inner join 自己看情况用追问



在 text里 输入要查询的内容 那样的 该怎么做 新手 写详细点 谢谢

追答

SELECT * FROM a LEFT JOIN b ON a.a1=b.b1 AND a.a2=b.b2 LEFT JOIN c ON a.a1=c.c1 AND a.a2=c.c2 WHERE 1; left join right join inner join WHERE a.a1=$_POST['textfield'];

追问

还是不行啊 麻烦您连静态页面的一起写上 谢谢啊

追答



然后你在test.PHP里用

"SELECT * FROM a LEFT JOIN b ON a.a1=b.b1 AND a.a2=b.b2 LEFT JOIN c ON a.a1=c.c1 AND a.a2=c.c2 WHERE 1; left join right join inner join WHERE a.a1= " .$_POST['textfield']; 语句执行查询 大概就是在这么个意思

追问

方便加下你qq吗 用不懂的以后我可以直接问你 921521900 这是我的

本回答被提问者采纳
第2个回答  2015-06-03
有多种方法

1 普通方法

select * from table1,table2

2 left join right join 等方法

select * from table1 t1 left join table2 t2 on t1.id = t2.id

3 UNION 方法

select * from table1 union select * from table2

4 嵌套查询方法

select * from table1 where id in (select pid from table2 where pid > 10)
相似回答