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 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题