在php中显示数据库中的产品

时间:2015-12-01 05:21:59

标签: php mysql bootstrapping

我想在存储在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行的行,当它已经定义时。

2 个答案:

答案 0 :(得分:0)

错误是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>

答案 1 :(得分:0)

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

您必须在php标记之间留出空格,并像这样<?php include 'databaseconfile.php';