dqh1992 2013-12-18 13:34
浏览 72
已采纳

PHP / MySQL INNER JOIN三倍的行数?

I have a system where I getting images out of my database, but when it does that, there is 3x of the same images.

I have tried with different ways, DISTINCT and such, but I have no clue how I fix this.

Here is my query code:

<?php
$id = $_GET['id'];

$query = "SELECT DISTINCT * FROM billeder INNER JOIN album ON fk_album_ID = $id";

$result = mysqli_query($con, $query);

while($row = mysqli_fetch_assoc($result))
{
    $thumb_src = 'billeder/thumb_'.$row['billeder_sti'];
    $full_src = 'billeder/'.$row['billeder_sti'];

    echo "
            <div class='ikon'>
                <a href='$full_src'>
                    <img src='$thumb_src' alt='' />
                </a>
            </div>
    ";
}

?>

Hope someone can help me on the way to fix this :)

  • 写回答

2条回答 默认 最新

  • douzhang8144 2013-12-18 13:43
    关注

    JOIN must be used with two tables columns. See example:

    SELECT * FROM tableA a INNER JOIN tableB b ON a.id = b.a_id;
    

    What you're trying to make is something like this:

    "SELECT DISTINCT * FROM billeder INNER JOIN album ON 
        billeder.fk_album_ID = album.album_id WHERE billeder.id = $id"
    

    You shouldn't pass an argument to the JOIN. The arguments must be used on the WHERE clause.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?