duanpin9531 2015-10-28 18:03
浏览 41

无法在for循环中添加链接

I am tryig to make a photo gallery on my website. I have a small problem with making link on images I have in for loop

Since You requested full code here it is:

<html>
<head>
    <meta charset="UTF-8">
    <title>Fotečky</title>
    <style>
        .foto{
            position: relative;
            display: inline-block;
            text-align: center;
            width: 200px;
            border: solid;
            margin-left: 6%;
        }
        #date{
            position: relative;
            text-align: center;
            width: 200px;
        }
        a { color: #000000; text-decoration: none; }
        .menu { 
            background-color: #FF9933;
            height: 10%;
            line-height: 300%;
        }
    </style>
</head>
<body>

    <div class="menu">
        <a href="insert.php"><center><h2>Upload photo</h2></center></a>
    </div>
    <br>

    <?php

            mb_internal_encoding("UTF-8");

            $connect = mysql_connect("","","") or die("Couldn't connect");
            mysql_set_charset('utf8',$connect);
            mysql_select_db("") or die("Couldn't find db");

            $SQLCommand = "SELECT * FROM foto";
            $result1 = mysql_query($SQLCommand); $database = array(); $index = 1; // make a new array to hold all your data
            while($row1 = mysql_fetch_assoc($result1)) // loop to give you the data in an associative array so you can use it however.
            {
                $database[$index] = $row1;

                $index++;
            }


            for ($i=1; $i < count($database); $i++) {
                echo '<a href="photo.php?id='.$database[$i]['id'].'">';
                echo '<div class="foto">';
                echo '<img title="'.$database[$i]['description'].'" alt="'.$database[$i]['description'].'" src="data:image/jpg/png/jpeg;base64,'.base64_encode( $database[$i]['image'] ).'" width="200px"/>';
                echo "<div id='date'>".$database[$i]['uploaded']."</div>";
                echo '</div>';
                echo '</a>';

                if ((($i % 4) == 0) && ($i != 0)) {
                    echo '<br><br>';
                }
            }
    ?>

</body>

I want to display image one by one and be able to click on them -> link that brings me to photo.php?id= with id of that image. (id is from 1 to n)

db sructure: enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了