我在mysql db中有一个2表。我想从这两个表中获取所有数据。表名如下:
tutor_signup_form
tutor_signup_edu_psle
因此我正在使用以下sql查询但无法获得结果。
$tutor_id = (int) $_GET['tutor_id'];
$query = mysql_query("SELECT tutor_signup_form . *, tutor_signup_edu_psle . * FROM
tutor_signup_form INNET JOIN tutor_signup_edu_psle ON tutor_signup_form.tutor_id = '$tutor_id'");
$result = mysql_fetch_array($query);
注意:两个表都有相同的tutor_id
列。
3表的新更新:
$query = mysql_query("SELECT tutor_signup_form . *, tutor_signup_edu_psle . *,
tutor_signup_edu_olevel . * FROM tutor_signup_form
INNER JOIN tutor_signup_edu_psle ON tutor_signup_form.tutor_id = tutor_signup_form.tutor_id ,
INNER JOIN tutor_signup_edu_olevel ON tutor_signup_form.tutor_id =
tutor_signup_edu_olevel.tutor_id
where tutor_signup_form.tutor_id = '$tutor_id' ");
$result = mysql_fetch_array($query);
答案 0 :(得分:0)
试试这个
SELECT * FROM
tutor_signup_form ts1 INNER JOIN
tutor_signup_edu_psle ts2 ON ts1.tutor_id = ts2.tutor_id
and ts1.tutor_id='$tutor_id'
答案 1 :(得分:0)
您的SQL查询应该是这样的,您也可以使用表名的别名
$query = mysql_query("SELECT tf.*, te.* FROM tutor_signup_form AS tf INNER JOIN tutor_signup_edu_psle AS te ON tf.tutor_id = te.tutor_id WHERE tf.tutor_id = '$tutor_id'");
这可能对你有用
答案 2 :(得分:0)
在ON中你不能给$ tutor_id你需要给其他表格列参考如
ON tutor_signup_form.tutor_id = tutor_signup_form.tutor_id
并在where子句中提供$ tutor_id的过滤器。所以你的查询看起来像
$query = mysql_query("SELECT tutor_signup_form . *, tutor_signup_edu_psle . * FROM
tutor_signup_form INNER JOIN tutor_signup_edu_psle ON tutor_signup_form.tutor_id = tutor_signup_form.tutor_id where tutor_signup_form.tutor_id = '$tutor_id'");
此外,我发现你拼错了INNER JOIN到INNET JOIN。