0

您好,提前感谢您的回答。我有两张表,曲目(有关音乐曲目的信息、标题、长度、cd_id..etc)和purchd_items(购买的曲目、cd_id、user_id..etc)。我有这个查询:

函数蓝色($id)

{
    $user_id = $this->tank_auth->get_user_id();

    $query = $this->db->query("SELECT tracks.id, tracks.track_id, tracks.cd_id, tracks.title, tracks.lenght, tracks.price, tracks.file, tracks.preview, tracks.hash, purchd_items.cd_id, purchd_items.name FROM tracks LEFT JOIN purchd_items ON tracks.cd_id = purchd_items.cd_id WHERE purchd_items.user_id = $user_id AND tracks.cd_id = $id GROUP BY tracks.title, purchd_items.name ORDER BY tracks.track_id");
    return $query->result();    

}

我正在尝试检查两个表是否匹配并显示轨道表中的所有信息以及purchd_items表中的匹配项目,这些项目将替换轨道表中的条目。如果用户已经购买了任何曲目,我想显示下载链接而不是通常的购买曲目链接。我猜有点像 iTunes。

我有点能够使用上面的查询来完成这项工作,但是返回数组中的项目数乘以purchd_items表中的条目数,我无法摆脱重复项。

希望我在这里有意义!谢谢!

4

1 回答 1

0

我想到了!

选择tracks.id,tracks.track_id,tracks.cd_id,tracks.title,tracks.lenght,tracks.price,tracks.file,tracks.preview,tracks.hash,purchd_items.cd_id,purchd_items.name 从轨道左连接purchd_items ON track.cd_id = purchd_items.cd_id AND purchd_items.name = tracking.title AND purchd_items.user_id = $user_id WHERE tracking.cd_id = $id ORDER BY tracking.id

于 2013-06-01T07:57:55.913 回答