为 products.php 文件中的每个产品创建单独的 .php?id= 链接
Creat individual .php?id= links for each of the products in products.php file
在我的产品页面上,有几个不同的产品网格(使用 bootstrap 创建),其中显示了我的所有产品。我想做的是为页面上的每个产品创建详细页面。
products.php:
<?php
session_start();
include('inc/config.php');
?>
<html>
<body>
some content
<div class="row">
<?php
$query=mysql_query("select*from cars");
while($data=mysql_fetch_assoc($query)){
?>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="text-center">
<?php echo "<h2>".$data['make']." ".$data['model']." </h2>"; ?></h4>
</div>
<div class="panel-body text-center">
<p class="lead">
<?php echo '<img src="cartest/'.$data['image'].'" class="img-responsive" />'; ?></p>
</div>
<ul class="list-group list-group-flush text-center">
<li class="list-group-item"><i class="icon-ok text-danger"></i><?php echo "<h4>".$data['price']." </h4>"; ?></li>
<li class="list-group-item"><i class="icon-ok text-danger"></i>Unlimited projects</li>
<li class="list-group-item"><i class="icon-ok text-danger"></i>27/7 support</li>
</ul>
<div class="panel-footer">
<?php echo '<a class="btn btn-lg btn-block btn-default" a href="product-details.php?id='.$data['carId'].'">Details</a>';?>
</div>
</div>
</div>
<? } ?>
</div>
</body>
</html>
产品-details.php:
<?php
session_start();
include('inc/config.php');
?>
<html>
<body>
some content
<div class="container-fluid">
<?php
$id = $_GET['carId'];
$query = mysql_query("SELECT * FROM cars WHERE carId='$id'") or die(mysql_error());
$data = mysql_fetch_array($query);
?>
<div>
<?php echo '<img alt="" src="cartest/'.$data['image'].'"></a>'; ?>
</div>
如您所见,我设法为每个产品创建了单独的链接,但是有没有一种方法可以使用类似于主模板的东西来显示单独的页面,它会根据具有的产品更改内容部分被点击?还是我必须为每个产品创建无数页面?
提前致谢
如果你想改变模板中的东西,你需要喜欢它。
for.eg。对于独特的背景,你可以使用这样的东西:
<div id="product" style="background: url($mybgurl)"></div>
在这种情况下 $mybgurl
它是 url 此产品的图像,从数据库中获取。
P.S: Google 用于 MVC 或模板引擎。
在我的产品页面上,有几个不同的产品网格(使用 bootstrap 创建),其中显示了我的所有产品。我想做的是为页面上的每个产品创建详细页面。 products.php:
<?php
session_start();
include('inc/config.php');
?>
<html>
<body>
some content
<div class="row">
<?php
$query=mysql_query("select*from cars");
while($data=mysql_fetch_assoc($query)){
?>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="text-center">
<?php echo "<h2>".$data['make']." ".$data['model']." </h2>"; ?></h4>
</div>
<div class="panel-body text-center">
<p class="lead">
<?php echo '<img src="cartest/'.$data['image'].'" class="img-responsive" />'; ?></p>
</div>
<ul class="list-group list-group-flush text-center">
<li class="list-group-item"><i class="icon-ok text-danger"></i><?php echo "<h4>".$data['price']." </h4>"; ?></li>
<li class="list-group-item"><i class="icon-ok text-danger"></i>Unlimited projects</li>
<li class="list-group-item"><i class="icon-ok text-danger"></i>27/7 support</li>
</ul>
<div class="panel-footer">
<?php echo '<a class="btn btn-lg btn-block btn-default" a href="product-details.php?id='.$data['carId'].'">Details</a>';?>
</div>
</div>
</div>
<? } ?>
</div>
</body>
</html>
产品-details.php:
<?php
session_start();
include('inc/config.php');
?>
<html>
<body>
some content
<div class="container-fluid">
<?php
$id = $_GET['carId'];
$query = mysql_query("SELECT * FROM cars WHERE carId='$id'") or die(mysql_error());
$data = mysql_fetch_array($query);
?>
<div>
<?php echo '<img alt="" src="cartest/'.$data['image'].'"></a>'; ?>
</div>
如您所见,我设法为每个产品创建了单独的链接,但是有没有一种方法可以使用类似于主模板的东西来显示单独的页面,它会根据具有的产品更改内容部分被点击?还是我必须为每个产品创建无数页面? 提前致谢
如果你想改变模板中的东西,你需要喜欢它。 for.eg。对于独特的背景,你可以使用这样的东西:
<div id="product" style="background: url($mybgurl)"></div>
在这种情况下 $mybgurl
它是 url 此产品的图像,从数据库中获取。
P.S: Google 用于 MVC 或模板引擎。