【问题标题】:Display products from database in php在 php 中显示数据库中的产品
【发布时间】:2015-12-01 05:21:59
【问题描述】:

我想在存储在 mysql 数据库中的 php 页面中显示产品详细信息。 我的php页面如下:

 <?phpinclude 'databaseconfile.php';
    $sql = "select * from book";
    $result = mysql_query($sql);
    ?>
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>Shop | ShareMyBook</title>
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/font-awesome.min.css" rel="stylesheet">
        <link href="css/prettyPhoto.css" rel="stylesheet">
        <link href="css/animate.css" rel="stylesheet">
        <link href="css/main.css" rel="stylesheet">
        <link href="css/responsive.css" rel="stylesheet">     
        <link rel="shortcut icon" href="images/ico/favicon.ico">
        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
        <link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
        <link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch- icon-57-precomposed.png">
    </head>
    <body>
    <div class="col-sm-4">
        <div class="product-image-wrapper">
            <div class="single-products">
                <div class="productinfo text-center">
                    <?phpwhile ($row = mysql_fetch_array($result))
                    {?>
                    <img src="images/home/" alt="" />
                    <h2><?php echo $row['Book_Name']; ?></h2>
                    <p>Book 10</p>
                    <?php}?>
                </div>
                <div class="product-overlay">
                    <div class="overlay-content">
                        <h2>Price</h2>
                        <p>Book 10</p>
                        <a href="#" class="btn btn-default view-item"><i class="glyphicon glyphicon-eye-open"></i>view Book</a>
                    </div>
                </div>

            </div>
            <div class="choose">
                <ul class="nav nav-pills nav-justified">
                    <li><a href="#"><i class="fa fa-plus-square"></i>Add to  wishlist</a></li>
                    <li><a href="#"><i class="fa fa-shopping-cart"></i>Add to  cart</a></li>
                </ul>
            </div>
        </div>
    </div>
    </body>
    </html>

当我尝试运行此页面时,它显示 - 注意:未定义变量:第 32 行的行,当它已经定义时。

【问题讨论】:

标签: php mysql bootstrapping


【解决方案1】:

错误是php和while循环之间需要的空间。我已经在评论中告诉过你。替换这段代码:

将第一行替换为:

<?php include 'databaseconfile.php';

和:

<div class="productinfo text-center">
   <?php while ($row = mysql_fetch_array($result))
     {?>
       <img src="images/home/" alt="" />
       <h2><?php echo $row['Book_Name']; ?></h2>
       <p>Book 10</p>
  <?php}?>
</div>

【讨论】:

  • ...连同第一行,应该是&lt;?php include 'databaseconfile.php';(注意&lt;?php后面的空格)
  • 是的,第一行也是同样的问题。
【解决方案2】:

错误在第一行。&lt;?phpinclude 'databaseconfile.php';

您必须在 php 标签之间留出空格并包含这样的&lt;?php include 'databaseconfile.php';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2017-04-08
    相关资源
    最近更新 更多