图片库——选择最先显示的图片

发布于 2024-12-09 02:30:47 字数 2245 浏览 2 评论 0原文

我有基于 jQuery scrip 的照片库[来自: http://coffeescripter.com/code/ad-画廊/

图像存储在 mySQL 数据库中。我有一个包含画廊列表的页面,其中显示每个画廊的前五张图像。单击任何图像都会移动到图库并从第一张图像开始显示。

我想以这样的方式做到这一点:如果用户单击第二个图像,显示应该从第二个图像开始,如果用户单击第三个图像,显示应该从第三个图像开始等等。

这是一些代码,我到目前为止:

/* galleries.php */
    <?php
        $idg = $_GET["idg"];
        if (file_exists(GALLERY.'galleries.php') && $idg == '') 
        {
            require_once(GALLERY.'list_galleries.php');
        }
        else if (file_exists(GALLERY.'galleries.php') && $idg != '' )
        {
            require_once(GALLERY.'view_gallery.php');
        }
    ?>

/* list_gallery.php */

<?php

    $sql_gal = "SELECT id_g, nazwa FROM page_gallery WHERE widok=1";
    $res_gal = @mysql_query($sql_gal);
    $n = mysql_num_rows($res_gal);

    while ($row_gal = @mysql_fetch_array($res_gal)){

        $galName = $row_gal["nazwa"];

        $idg = $row_gal["id_g"];

        $sql_gal_con = "SELECT desc, img FROM page_gallery_con
            WHERE id_g='$idg' ORDER BY order ASC LIMIT 5";
        $res_gal_con = @mysql_query($sql_gal_con);


        echo '<table class="galleryTable">';
        echo '<tr >';
        echo '<td colspan="4">';
        echo '<a href="?p=13&idg='.$idg.'" class="galleryName" >'.$galName.'</a>';
        echo '</td>';
        echo '<td class="galleryCount">';
        echo '</td>';
        echo '</tr>';
        echo '<tr class="galleryRow">';

        while ($row_gal_con = @mysql_fetch_array($res_gal_con)){

            $desc = $row_gal_con["desc"];
            $img = $row_gal_con["img"];

            echo '<td class="galleryCell">';
                            echo '<a href="?p=13&idg='.$idg.'"><img src="'.GALLERY_DIR.'min/'.$img.'" alt="'.$desc.'" /></a>';
            echo '</td>';

        }
        echo '</tr>';
        echo '</table>';
    }

?>

我根据 http://webdev.plentyinfo.com/tag/ad-gallery/

I have photo gallery based on jQuery scrip[t from: http://coffeescripter.com/code/ad-gallery/.

Images are stored in mySQL database. I have a page with list of galleries, which displays first five images from each gallery. Clicking at any of image moves to gallery and starts displaying from first image.

I would like to do that in a such way: if user clicks on second image, displaying should start from second image, if user clicks on third image, displaying should start from third image etc.

Here is some code, which I have so far:

/* galleries.php */
    <?php
        $idg = $_GET["idg"];
        if (file_exists(GALLERY.'galleries.php') && $idg == '') 
        {
            require_once(GALLERY.'list_galleries.php');
        }
        else if (file_exists(GALLERY.'galleries.php') && $idg != '' )
        {
            require_once(GALLERY.'view_gallery.php');
        }
    ?>

/* list_galleries.php */

<?php

    $sql_gal = "SELECT id_g, nazwa FROM page_gallery WHERE widok=1";
    $res_gal = @mysql_query($sql_gal);
    $n = mysql_num_rows($res_gal);

    while ($row_gal = @mysql_fetch_array($res_gal)){

        $galName = $row_gal["nazwa"];

        $idg = $row_gal["id_g"];

        $sql_gal_con = "SELECT desc, img FROM page_gallery_con
            WHERE id_g='$idg' ORDER BY order ASC LIMIT 5";
        $res_gal_con = @mysql_query($sql_gal_con);


        echo '<table class="galleryTable">';
        echo '<tr >';
        echo '<td colspan="4">';
        echo '<a href="?p=13&idg='.$idg.'" class="galleryName" >'.$galName.'</a>';
        echo '</td>';
        echo '<td class="galleryCount">';
        echo '</td>';
        echo '</tr>';
        echo '<tr class="galleryRow">';

        while ($row_gal_con = @mysql_fetch_array($res_gal_con)){

            $desc = $row_gal_con["desc"];
            $img = $row_gal_con["img"];

            echo '<td class="galleryCell">';
                            echo '<a href="?p=13&idg='.$idg.'"><img src="'.GALLERY_DIR.'min/'.$img.'" alt="'.$desc.'" /></a>';
            echo '</td>';

        }
        echo '</tr>';
        echo '</table>';
    }

?>

I have found proper solution based on tips from http://webdev.plentyinfo.com/tag/ad-gallery/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云醉月微眠 2024-12-16 02:30:47

只需添加一个 if 条件来检查您的 $_GET 变量是否已设置。例如,在第二个查询之前,像这样更改代码

 if(isset($_GET['idg']))
 $idg=$_GET['idg'];
 else
 $idg = $row_gal["id_g"];

just add a if condition to check if your $_GET variable is set or not. For example before your second query change your code like this

 if(isset($_GET['idg']))
 $idg=$_GET['idg'];
 else
 $idg = $row_gal["id_g"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文