douming4359 2014-11-22 16:24
浏览 27

如何在html中显示数据库中的数据[关闭]

I'm trying to pull my information from the database, which I've managed, and store it in a table. However I keep getting errors. Can anyone see the problem?

<?php
//Make connection to database
$connection = mysqli_connect('localhost', 'root', '', 'c3438525');
//Display heading

//run query to select all records from customer table
//store the result of the query in a variable called $result

//Use a while loop to iterate through your $result array and display
//each field wrapped in appropriate HTML table tags.



//include 'connection.php'  

include 'products.css'
$query="SELECT * FROM products";

$results=mysqli_query($connection, $query);

while($row=mysqli_fetch_assoc($results)){

    ?>



<table class='display'>
<tr><td><?php echo "<img src=$rows[$product_image] height='200px' width='200px'>"  ?></td></tr>

<tr>
<td><b><?php echo "$rows[$product_name]" ?></td>
<td><b><?php echo "Price: £ $rows[$price]" ?></td>
<td><b><?php echo "Picture: $rows[$product_image]" ?></td>

</tr>


</table>
    <?php   
}
?>
  • 写回答

2条回答 默认 最新

  • duandou2763 2014-11-22 16:28
    关注

    You need to provide the array keys as strings and also terminate statements with a semicolon.

    <table class="display">
    <tr>
        <td>
        <?php
           // you can also write an array value directly into a string
           echo "<img src=\"{$rows['product_image']}\" height=\"200px\" width=\"200px\">";
        ?>
        </td>
    </tr>
    <tr>
        <td><b><?php echo $rows['product_name']; ?></b></td>
        <td><b><?php echo "Price: £ " . $rows['price']; ?></b></td>
        <td><b><?php echo "Picture: " . $rows['product_image']; ?></b></td>
    </tr>
    </table>
    

    In addition you should be closing those </b> tags (but <strong> tags are preferred over <b>)

    It is a better practice to include styles in the <head> of the document

    <head>
        <link rel="stylesheet" type="text/css" href="products.css">
    </head>
    

    but include 'products.css'; will work (can't forget those semicolins)

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答