我正在用PHP和MYSQL创建一个视频库。该图库下方有视频缩略图和文字标题。当用户单击图像缩略图或文本标题时,它将转到另一个将显示视频及其下的标题的网页。我希望用户点击的标题与转发到视频网页时视频下显示的标题相同。如何在点击时传递缩略图下的标题,以便将其发送到其他网页?我希望点击的标题显示在视频下方。 这是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>
这是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>
答案 0 :(得分:0)
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>