1

如何更改此代码,使其一次仅显示一个图像,并带有下一个和上一个按钮以浏览图像。

我使用了这个网站的代码

$sql = "select * from people";
    $result = mysql_query($sql) or die ("Could not access DB: " .  mysql_error());
    while ($row = mysql_fetch_assoc($result))
    {
        echo "<div class=\"picture\">";
        echo "<p>";

// Note that we are building our src string using the filename from the database
        echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />";
        echo $row['fname'] . " " . $row['lname'] . "<br />";
        echo "</p>";
        echo "</div>";

如果没有人愿意提供帮助,他们能否向我指出可能有答案的教程或网站的方向。我是 php 新手,因此非常感谢所有帮助。

4

2 回答 2

1
$page = $_GET['page'];    
$sql = "select * from people LIMIT $page,1";
while(...){
  ...
  $next_page = $page+1;
  $prev_page = $page-1;

  $next_btn = "<a href='script.php?page=".$next_page."'>Next</a>";
}

这是一个基本的实现,不要忘记否定/最大验证和 mysql 注入!

于 2012-07-14T22:48:51.260 回答
0

图像裁剪。您可以在 url 中传递参数以获得所需的输出图像大小,如下所示image.php?src=img/random.jpg&w=300&h=200

<?php
header("Content-type: image/jpeg");
$image = imagecreatefromjpeg($_GET['src']);

$thumb_width = $_GET['w'];
$thumb_height = $_GET['h'];

$width = imagesx($image);
$height = imagesy($image);

$original_aspect = $width / $height;
$thumb_aspect = $thumb_width / $thumb_height;

if($original_aspect >= $thumb_aspect) {
   // If image is wider than thumbnail (in aspect ratio sense)
   $new_height = $thumb_height;
   $new_width = $width / ($height / $thumb_height);
} else {
   // If the thumbnail is wider than the image
   $new_width = $thumb_width;
   $new_height = $height / ($width / $thumb_width);
}

$thumb = imagecreatetruecolor($thumb_width, $thumb_height);

// Resize and crop
imagecopyresampled($thumb,
                   $image,
                   0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
                   0 - ($new_height - $thumb_height) / 2, // Center the image vertically
                   0, 0,
                   $new_width, $new_height,
                   $width, $height);
imagejpeg($thumb);
?>

在一次将一个图像放在页面上并浏览它们方面,使用上一个和下一个按钮。那将需要一些javascript来实现。

有很多不错的画廊可以一次显示一张图片,而且他们已经解决了图片调整大小的问题。看看这里

于 2012-07-14T23:54:32.793 回答