dourao1968 2016-09-01 05:43
浏览 32
已采纳

如何使用PHP和MYSQL将缩略图下的标题文本传递到另一个网页

I am creating a video gallery in PHP and MYSQL. The gallery have video thumbnail and text captions under them. When the user click on the image thumbnail or the text caption, it will take them to another web page that will display the video and the caption under it. I want the caption that the user clicked on to be the same caption that is displayed under the video when they are forwarded to the video web page. How do I pass the caption that is under my thumbnail when its clicked, so it can be send to another webpage? I want the caption that is clicked on to displayed under the video. This is the code for gallery.php :

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<?php
$con=mysqli_connect("localhost","root","","image_display");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$result=mysqli_query($con,"select * from table1");

while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) 
   {
       $image_link = $row['imagelink'];
       $image_path = $row['image1'];
       $caption = $row['caption'];

       echo "<div id='gallery'>";
       echo "<a href=".$image_link.val=$caption" value="fixed text"><img src=".$image_path." width='150' height='150' alt='' /> <br>";
       echo $caption."</a>"; echo "</div>";

   }


?>
</body>
</html>

This is the code for display_video.php:

<!DOCTYPE html>
<html>
  <head>
    <title>PHP!</title>
  </head>

  <body>


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

      $embedvideo; //This will hold embed video code

       ?>

     <div id="watchvideo" align="center">
     <?php
     echo "<h1>$caption=</h1>";
     echo  $embedvideo; ?>

     <p><a href="gallery.php">Back to gallery</p>

     </div>


  </body>
</html>
  • 写回答

1条回答 默认 最新

  • dongpi9164 2016-09-01 06:11
    关注

    Try this, hopefully help you:

    gallery.php

    <!DOCTYPE html>
        <html>
        <head>
            <title>Page Title</title>
        </head>
        <body>
    
            <?php
    
            $con = mysqli_connect("localhost","root","","image_display");
    
          // Check connection
            if (mysqli_connect_errno())
            {
                echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }
            $result=mysqli_query($con,"select * from table1");
    
            while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) 
            {
                $image_link = $row['imagelink'];
                $image_path = $row['image1'];
                $caption = $row['caption'];
    
                echo "<div id='gallery'>";
    
                echo "<a href=".$image_link."?caption=".urlencode ($caption)." value='fixed text'><img src=".$image_path." width='150' height='150' alt='' /> <br>";
                echo $caption."</a>"; echo "</div>";
    
            }
    
    
            ?>
        </body>
        </html>
    

    display_video.php

        <!DOCTYPE html>
    <html>
    <head>
      <title>PHP!</title>
    </head>
    
    <body>
    
    
      <?php
      $caption=$_GET['caption'];
    
      $embedvideo = "This will hold embed video code";
    
      ?>
    
      <div id="watchvideo" align="center">
       <?php
       echo "<h1>".$caption."</h1>";
       echo  $embedvideo; ?>
    
       <p><a href="gallery.php">Back to gallery</p>
    
     </div>
    
    
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址