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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据