简体   繁体   English

PHP代码显示数据库数据

[英]PHP code to display db data

Hi guys I have a problem with my PHP, What I am trying to achieve is this: 嗨,大家好,我的PHP有问题,我想要达到的目的是:

<li><a href="main.html" class="title">Product name from DB</a>
        <strong>&pound;499<a href="main.html"><img src="images/thumb.png" alt="Product name from DB"/></a></strong>
  </li>

and here is my code with php: 这是我的PHP代码:

<ul id="items">
    <?php while($product_data = mysql_fetch_array($query_product_result))
  {
    $num_rows_products = $num_rows_products - 1;
    Print "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . " <strong> Name:  " . $product_data["title"] . "</strong></a>";
    Print "<strong>Price: &pound;" . $product_data["price"] .  "'><img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
    if($num_rows_products > 0)
            Print '<p> nu products ? wtf</p>';
  }
  ?>

For some reason all I get is an image with a hyperlink, no title and no price, any chance you can spot the mistake? 由于某种原因,我得到的只是一张带有超链接的图像,没有标题,也没有价格,您有机会发现错误吗?

Your not closing the <a> tag properly. 您没有正确关闭<a>标记。 See the code below. 请参见下面的代码。 Notice the missing ">" in your code? 注意代码中缺少的“>”吗?

Print "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . "'> <strong> Name:  " . $product_data["title"] . "</strong></a>";
    Print "<strong>Price: &pound;" . $product_data["price"] .  "<img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";

Use Echo instead. 请改用Echo Print won't displays concatenated string. Print不会显示串联的字符串。

 <ul id="items">
        <?php while($product_data = mysql_fetch_array($query_product_result))
      {
        $num_rows_products = $num_rows_products - 1;
        echo "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . " <strong> Name:  " . $product_data["title"] . "</strong></a>";
        echo "<strong>Price: &pound;" . $product_data["price"] .  "'><img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
        if($num_rows_products > 0)
                echo '<p> nu products ? wtf</p>';
      }
      ?>

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

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