开发者

How do I get this while loop to dynamically produce this html?

I am building a picture gallery, that uses this code to display each product I have:

<div class="feature">
            <a href="#"><imagetag alt="Image Caption"srcs=""></a>
            <div>
                <p>
                    This is some information that can go along with an image.
                    Anything can be placed here, including images.
                </p>
            </div>
</div>

I need to create a while loop, that takes all the products in my database, and creates a div of the "feature" class for every instance. I have problems know exactly which symbols need to be escaped and etc. Your help is greatly appreciated.

here is my start:

   <?php
 ($product_set 开发者_运维百科= mysql_fetch_assoc($query)) {
  print("<div class="feature"> <a href="#"><imagetage alt="Image Caption" srcs=$product_set[products_image]></a>"


    );}
   ?>


If you are in a string, every doublequote should be escaped. Because it will close your string.

<?php
    ($product_set = mysql_fetch_assoc($query)) 
    {
        print "<div class=\"feature\"><a href=\"#\"><img alt=\"Image Caption\" src=" . $product_set['products_image'] . "></a>";
    }
?>

Fun thing is, I got a link from someone on stackOverflow about PHP templating. Which was using Smarty. So you don't have to use these print states anymore.


Have you tried:
print(htmlentities($my_html_string))
or htmlspecialchars? htmlentities converts all characters that have one to their HTML escape sequence, while htmlspecialchars converts only those that have meaning in HTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜