duanao2585 2018-09-23 11:38
浏览 16

PHP画廊专辑

i am writing a php script that retrieves images from a database and shows them on page inside an album , each album contains several images...

here is an example for the code below :

$sql = "SELECT * FROM tbl_album where status='process' ORDER BY albumid DESC LIMIT $start_from, 12";

<?php

$rs_result = mysql_query ($sql,$con);

while ($row = mysql_fetch_assoc($rs_result)) 
{
  $aid=$row['albumid'];
  $aimage=$row['image'];
  $aname=$row['name'];
  $astatus=$row['status'];

  echo '<div class="col-lg-4 col-md-6 col-sm-6 agile_gallery_grid">';
  echo '<div class="hover ehover14">';

  ?>
  <?php
  echo"<a href='#details?d=$aid' onclick='showfunction()'>";        
  echo "<img src='admin/acatch/$aimage' class='img-responsive' alt='$aname' width='200' height='200' data-picture_id='$aid'>";
  echo'</a>';
}
?>

this code shows all the albums contained in the database , but what i want to do is that when i click on the album cover , i want to display the images inside it on the same page , but i am not able to pass the album id to another php script on the same page to do this, please if anyone can help thank u in advance

  • 写回答

1条回答 默认 最新

  • douba1617 2018-09-23 12:20
    关注

    Have a look at the following code:

    <?php 
    $sql = "SELECT * FROM tbl_album where status='process' ORDER BY albumid DESC  LIMIT $start_from, 12";
    $rs_result = mysql_query($sql, $con);
    while($row = mysql_fetch_assoc($rs_result)):
        $aid=$row['albumid']; 
        $aimage=$row['image']; 
        $aname=$row['name']; 
        $astatus=$row['status'];
        ?>
        <div class="col-lg-4 col-md-6 col-sm-6 agile_gallery_grid">
            <div class="hover ehover14">
                <a href='#details?d=$aid' onclick='showfunction()'>
                    <img src="admin/acatch/<?=$aimage?>" class="img-responsive" alt="<?=$aname?>" width="200" height="200" data-picture_id="<?=$aid?>">
                </a>
            </div>
        </div>
        <div class="gallery_album" id="gallery_album_<?=$row['albumid']?>">
        <?php 
            /**
             *  now collect all images associated with each album by using $aid
             */
            $sql_images = "SELECT * FROM tbl_album_images WHERE fk_album_id = $aid";
            $images_result = mysql_query($sql_images, $con);
            while($image = mysql_fetch_assoc($images_result)):  
                ?>
                <div class="gallery_album_image"><img src="<?=$image['dir_and_filename']?>"></div>
                <?php 
            endwhile; 
            ?>
        </div>
    <?php endwhile; ?>
    

    What we are doing here is gettign all the albums as you allready does. But we introduce a subquery inside the first while-loop to fetch all associated images for each album.
    We put these images inside new div-container with a unique album id you can use to show or hide the actual album with your showfunction()
    Use CSS and javascript to show or hide accordingly.

    OBS! WARNING!! Your mysql queries, and the one I provided, is very very BAD!
    Have a look into prepared statement using php PDO or mysqli...

    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私