简体   繁体   中英

how to display an image in pagination?

How will i Display a picture with the same id here in my pagination.php? 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. You have to output them with php echo statement like that :

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

Also remebmer to escape output using htmlentities() to prevent XSS attacks.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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