-1

我有以下两个查询:

    $query2 = "SELECT DID,title,description,doc_type,time_added,date_added,
    downloadcount from docs where public='1' AND active='1' order by downloadcount 
    $sort limit $pagingstart, $config[items_per_page]";

    $query3 = "select members.ptitle, members.firstname, members.lastname from 
    members right join docs on members.userid=docs.userid";

我已经成功地完成了 RIGHT JOIN 以匹配两个表上的 USERID。

但是,我无法通过 downloadcount 获得订单以正确订购。电流输出如下:

请注意,对于此输出

  • Tylor 博士是 USERID 25
  • Raymond 先生是 USERID 1

用户名分为 3 个 - 标题、名字、姓氏

   USERNAME               | DOC NAME  |DOWNLOAD COUNT
--------------------------------------------------------    
    Dr. Fred Tyler        | DOC-A     | 3
    Mr. Raymond Franco    | DOC-B     | 1
    Dr. King Raymond      | DOC-C     | 0
    Mr. Raymond Franco    | DOC-Z     | 0

现在,我面临的问题是 DOC-A 实际上属于 My Raymond Franco,而 DOC-B 属于 Fred Tyler 博士。

有什么方法可以加入这两个表并按下载计数排序,而输出不会混乱?

提前致谢。

4

2 回答 2

0

为什么不只在一个 SELECT 中完成所有操作?

$query2 = "SELECT 
  members.ptitle, 
  members.firstname,      
  members.lastname,
  docs.DID,
  docs.title,
  docs.description,
  docs.doc_type,
  docs.time_added,
  docs.date_added,
  docs.downloadcount 
FROM members
INNER JOIN docs ON members.userid=docs.userid";
WHERE public='1' 
AND active='1' 
ORDER BY downloadcount 
$sort limit $pagingstart, $config[items_per_page]";
于 2013-10-15T08:54:49.707 回答
0

请尝试一下:

$query2 = "SELECT d.DID, d.title, d.description, d.doc_type, d.time_added, d.date_added, d.downloadcount,
members.ptitle, members.firstname, members.lastname 
from docs d
left join members on members.userid = d.userid
where d.public='1' AND d.active='1' 
order by d.downloadcount 
$sort limit $pagingstart, $config[items_per_page]";

我想对你来说是一本好书。

于 2013-10-15T08:51:22.450 回答