1

我怎样才能做出这样的事情(在 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 中给出的布尔值...

4

5 回答 5

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());

注意: 请不要mysql_*在新代码中使用函数。它们不再被维护并被正式弃用。看到红框了吗?改为了解准备好的语句,并使用PDOMySQLi -本文将帮助您决定使用哪个。如果您选择 PDO,这里有一个很好的教程

于 2013-03-07T13:12:04.533 回答
2

后面加空格

WHERE a.id=b.id AND a.id=c.id";

所以应该是:

WHERE a.id=b.id AND a.id=c.id ";
于 2013-03-07T13:12:27.570 回答
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);

订购前需要一个“空格”

于 2013-03-07T13:12:42.903 回答
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";   
于 2013-03-07T13:15:44.340 回答
0

应该是

 $query .= " ORDER BY a.prenume order(asc/desc)";

插入

 $query .= "ORDER BY a.prenume"; 

你需要在 ORDER BY 之前给空间

于 2013-03-07T13:11:32.943 回答