如何制作这样的东西(在SELECT命令中添加内容):
$query = "SELECT a.name,a.surname,b.email,c.phone
FROM users as a
inner join users_email as b
inner join users_phone as c
WHERE a.id=b.id AND a.id=c.id";
$query .= "ORDER BY a.surname";
$result = mysql_query($query,$con);
结果应为:
$query = "SELECT a.name,a.surname,b.email,c.phone
FROM users as a
inner join users_email as b
inner join users_phone as c
WHERE a.id=b.id AND a.id=c.id
ORDER BY a.name";
$result = mysql_query($query,$con);
$row=mysql_num_fields($result)
...但是它给出了一个错误:mysql_num_fields()期望参数1是资源,布尔值在第32行的C:\ xampp-portable \ htdocs \ db \ file.php中给出...
答案 0 :(得分:4)
在连接查询时始终提供space
。
$query = "SELECT a.name,a.surname,b.email,c.phone
FROM users as a
inner join users_email as b
inner join users_telefon as c
WHERE a.id=b.id AND a.id=c.id ";
$query .= " ORDER BY a.prenume";
^
还要练习mysql_error()
。
$result = mysql_query($query,$con) or die(mysql_error());
注意: Please, don't use mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。
答案 1 :(得分:2)
在
之后添加空格WHERE a.id=b.id AND a.id=c.id";
所以它应该是:
WHERE a.id=b.id AND a.id=c.id ";
答案 2 :(得分:2)
试试这个:
$query = "SELECT a.name,a.surname,b.email,c.phone
FROM users as a
inner join users_email as b
inner join users_telefon as c
WHERE a.id=b.id AND a.id=c.id";
$query .= " ORDER BY a.prenume";
$result = mysql_query($query,$con);
在订购依据之前需要'空格'
答案 3 :(得分:1)
$query = "SELECT a.name,a.surname,b.email,c.phone
FROM users as a
inner join users_email as b ON a.id=b.id
inner join users_telefon as c ON a.id=c.id
ORDER BY a.name";
答案 4 :(得分:0)
应该是
$query .= " ORDER BY a.prenume order(asc/desc)";
而不是
$query .= "ORDER BY a.prenume";
你需要在ORDER BY
之前给出空格