简体   繁体   English

如何在分页中显示图像?

[英]how to display an image in pagination?

How will i Display a picture with the same id here in my pagination.php? 我如何在我的pagination.php中显示具有相同ID的图片? i tried doing this 我尝试这样做

<td width="20%" valign="top"><a href="product.php?id=' . $id . '">
          <img style="border:#666 2px solid;" src="inventory_images/' . $id . '.jpg" width="150" height="102" border="1" /></a>
          </td>

but it wont work.. any possible way to display the image using pagination? 但它不能工作..使用分页显示图像的任何可能方法?

 for ($i = $start; $i < $end; $i++)
        {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }

                // echo out the contents of each row into a table
                echo "<tr>";
                echo '<td>' . mysql_result($result, $i, 'product_name') . '</td>';
                echo '<td>' . mysql_result($result, $i, 'price') . '</td>';
                echo '<td>' . mysql_result($result, $i, 'details') . '</td>';
                echo '<td>' . mysql_result($result, $i, 'category') . '</td>';
                echo '<td>' . mysql_result($result, $i, 'subcategory') . '</td>';
                echo '<td><a href="product.php?id=' . mysql_result($result, $i, 'id') . '">Click To View</a></td>';
                echo "</tr>"; 
        }

Probably you have to put in your code something like that : 可能您必须在代码中输入如下内容:

<td width="20%" valign="top">
  <a href="product.php?id=<?php echo $id; ?>">
    <img style="border:#666 2px solid;" src="inventory_images/<?php echo $id; ?>.jpg" width="150" height="102" border="1" />
  </a>
</td>

Check the generated source and adjust the code above. 检查生成的源并调整上面的代码。 Please keep in mind that in HTML you cannot put php variables directly. 请记住,在HTML中,您不能直接放置php变量。 You have to output them with php echo statement like that : 您必须使用php echo语句输出它们,如下所示:

<html>
  SOME HTML
  <div class="valueFromPhp"><?php echo $value; ?></div>
</html>

Also remebmer to escape output using htmlentities() to prevent XSS attacks. 还可以使用htmlentities()来逃避输出,以防止XSS攻击。

echo '
  <td> 
    <img width=100 src="../PHP/saved_images/'.mysql_result($result, $i, "bkimg").'"> 
  </td>
';  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM