1

このコードを変更して、一度に 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>";

誰も助けようとしない場合は、答えがあるかもしれないチュートリアルまたは Web サイトの方向性を教えてもらえますか。私は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);
?>

一度に 1 つの画像をページに配置し、それらをブラウズするには、[前へ] ボタンと [次へ] ボタンを使用します。それを実現するには、JavaScriptが必要です。

一度に 1 つずつ画像を表示する素敵なギャラリーがたくさんあり、それらは既に画像のサイズ変更の問題を処理しています。こちらをご覧ください

于 2012-07-14T23:54:32.793 に答える