用php显示数据库中的产品
我想在存储在mysql数据库中的php页面中显示产品详细信息。 我的php页面如下:用php显示数据库中的产品,php,mysql,bootstrapping,Php,Mysql,Bootstrapping,我想在存储在mysql数据库中的php页面中显示产品详细信息。 我的php页面如下: <?phpinclude 'databaseconfile.php'; $sql = "select * from book"; $result = mysql_query($sql); ?> <html> <head> <meta charset="utf-8"> <meta nam
<?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行上显示了Notice:Undefined variable:row,当它已经被定义时。错误是php和while循环之间需要的空间。我已经在评论中告诉过你了。替换这段代码: 将第一行替换为:
<?php include 'databaseconfile.php';
以及:
错误在第一行。php和while之间需要一个空格,正如上面所说的。。。使用而不是mysql_*函数,因为它已被弃用…与第一行一起使用,第一行中的相同问题应为“是”。
<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>