这里我无法从数据库中获取数据。我想要结果,因为当我点击类别时,结果应来自产品数据库,其中c_id
=来自数据库的类别
这里显示的菜单来自我的数据库表名=类别
当点击时,我应该将结果作为硬币选择器=得到页面右侧(与产品表中的硬币选择器相关的结果)。
我的类别数据库表是
产品表的数据库表是
<?php
$link = mysqli_connect("localhost", "root", "", "admin_login");
include 'header.php';
?>
<div class="container-fluid">
<div class="row">
<div class="col-lg-offset-1 col-lg-2">
<div class='panel panel-default'>
<?php
$query = "SELECT * FROM category";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_array($res))
{
?>
<div class='nav nav pills nav-stacked nav_custom'>
<li><a href='category.php?id=<?php echo $row['c_id']; ?>'><?php echo $row['c_name']; ?></a></li>
</div>
<?php
}
?>
</div>
</div>
<div class='col-lg-6'>
<div class="panel panel-info">
<div class="panel panel-body">
<?php
$c_id = $row["c_id"];
$query = "SELECT * FROM product WHERE c_id='.$c_id.' ";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_array($res))
{ ?>
<div class="col-lg-3">
<div class="panel panel-info">
<div class="panel-heading"><?php $row["product_name"]; ?>
</div>
<div class="panel-body">
<center>
<img src="image/product_image/'<?php echo $row["product_img"]; ?>'" alt="'<?php $row["product_name"]; ?> '" class="img-responsive" width="200px" height="200px">
</center>
</div>
<div class="panel-footer">
<a href="product_details.php?id=<?php echo $row["id"]; ?>" class="btn btn-info btn-block btn-xs">Details
</a>
<a href="contact.php?id=<?php $row["id"]; ?> " class="btn btn-info btn-block btn-xs"><span class="glyphicon glyphicon-credit-card"></span> Request Sample Quote
</a>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
<p><br></p>
<p><br></p>
<p><br></p>
<?php
include 'footer.php';
?>
答案 0 :(得分:0)
不是它的可变覆盖问题
你的查询中有语法错误。没有它不会覆盖问题。你传递变量id
以显示产品的问题
看到这里
<li><a href='category.php?id=<?php echo $row['c_id']; ?>'>
并且您正在尝试使用$c_id
获取不存在的产品。请参阅此处
<div class="panel panel-body">
<?php
$c_id = $row["c_id"];
query = "SELECT * FROM product WHERE c_id='.$c_id.' ";
$res = mysqli_query($link, $query);
然后你需要像这样访问id
if (isset($_GET['id'])) {
$c_id = $_GET['id'];
$query = "SELECT * FROM product WHERE c_id='$c_id' ";
$res = mysqli_query($link, $query);
//your `while` loop
}
请记住,您的查询对sql注入攻击使用prepared statement
完整代码
<?php
$link = mysqli_connect("localhost", "root", "", "admin_login");
include 'header.php';
?>
<div class="container-fluid">
<div class="row">
<div class="col-lg-offset-1 col-lg-2">
<div class='panel panel-default'>
<?php
$query = "SELECT * FROM category";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_array($res)){ ?>
<div class='nav nav pills nav-stacked nav_custom'>
<li><a href="category.php?id=<?php echo $row['c_id']; ?>">
<?php echo $row['c_name']; ?></a></li>
</div>
<?php
}
?>
</div>
</div>
<div class='col-lg-6'>
<div class="panel panel-info">
<div class="panel panel-body">
<?php
if (isset($_GET['id'])) {
$c_id = $_GET['id'];
$query = "SELECT * FROM product WHERE c_id='$c_id' ";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_array($res)) { ?>
<div class="col-lg-3">
<div class="panel panel-info">
<div class="panel-heading"><?php $row["product_name"]; ?>
</div>
<div class="panel-body">
<center>
<img src="image/product_image/'<?php echo $row["product_img"]; ?>'" alt="'<?php $row["product_name"]; ?> '" class="img-responsive" width="200px" height="200px">
</center>
</div>
<div class="panel-footer">
<a href="product_details.php?id=<?php echo $row["id"]; ?>" class="btn btn-info btn-block btn-xs">Details
</a>
<a href="contact.php?id=<?php $row["id"]; ?> " class="btn btn-info btn-block btn-xs"><span class="glyphicon glyphicon-credit-card"></span> Request Sample Quote
</a>
</div>
</div>
</div>
<?php }
} ?>
</div>
</div>
</div>
</div>
</div>
</div>
<p><br></p>
<p><br></p>
<p><br></p>
<?php
include 'footer.php';
?>