在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
画廊原型如下: 我们想要定义画廊的缩略图为两列。 This is how it works. Let’s say you want two cells in each row. When the first cell is inserted, 所以定义列用一个计数器和%取模结合起来比较简单。 define('COLS', 2); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> </body><?php // define number of columns in table define('COLS', 2); // create a connection to MySQL define('SHOWMAX', 6); // create a connection to MySQL $conn=mysqli_connect('localhost','root','sm159357','phpsolutions_gallery') or die("can not connect");// prepare SQL to get total records $getTotal = 'SELECT COUNT(*) FROM images'; // submit query and store result as $totalPix $total = mysqli_query($conn,$getTotal); $row = mysqli_fetch_array($total); $totalPix = $row[0]; // set the current page $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; // calculate the start row of the subset $startRow = $curPage * SHOWMAX; // prepare SQL to retrieve subset of image details $sql = "SELECT * FROM images LIMIT $startRow,".SHOWMAX; // submit the query (PDO) $result =mysqli_query($conn,$sql); // get any error messages // extract the first record as an array $row = mysqli_fetch_array($result); // get the name for the main image if (isset($_GET['image'])) { $mainImage = $_GET['image']; } else { $mainImage = $row['filename']; } // get the dimensions of the main image $imageSize = getimagesize('images/'.$mainImage); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> table{ float:left; } #main_image{ margin-left:40px; float:left; } </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Japan Journey <?php if (isset($title)) {echo "—{$title}";} ?> </title> <link href="assets/journey.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div > <h1>Japan Journey </h1> </div> <div > <div > <h1>Images of Japan</h1> <p >; if ($startRow+1 < $totalPix) { echo ' to '; if ($startRow+SHOWMAX < $totalPix) { echo $startRow+SHOWMAX; } else { echo $totalPix; } } echo " of $totalPix"; ?></p> <div > <table > <tr> <!--This row needs to be repeated--> <?php // initialize cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['filename'] == $mainImage) { $caption = $row['caption']; } ?> <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['filename']; ?>&curPage=<?php echo $curPage; ?>"><img src="images/thumbs/<?php echo $row['filename']; ?>" alt="<?php echo $row['caption']; ?>" width="80" height="54" /></a></td> <?php $row = mysqli_fetch_array($result); // increment counter after next row extracted $pos++; // if at end of row and records remain, insert tags if ($pos%COLS === 0 && is_array($row)) { echo '</tr><tr>'; } } while($row); // end of loop // new loop to fill in final row while ($pos%COLS) { echo '<td> </td>'; $pos++; } ?> </tr> <!-- Navigation link needs to go here --> <tr> <td><?php // create a back link if current page greater than 0 if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'">< Prev</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 2 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td><?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'">Next ></a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> </tr> </table> <div > <p><img src="images/<?php echo $mainImage; ?>" alt="<?php echo $caption; ?>" <?php echo $imageSize[3]; ?> /></p> <p><?php echo $caption; ?></p> </div> </div> </div> </div> </body> </html> </html>
|
2022-07-18
2022-08-16
2022-11-06
2022-08-18
2022-08-15
请发表评论