我正在尝试为我的作业建立一个小网站而且我被困在一个页面中。实际上,我的代码没有工作,因为没有显示任何内容,也没有显示错误。任何帮助,将不胜感激。提前谢谢..
<?php
include ("masterzone/php/mysqli.php");
if ($stmt = $db->prepare("SELECT tbl_name FROM listing_title where listing_title_ID=?")) {
$tpe = $_GET['type'];
$stmt->bind_param("i", $tpe);
$stmt->execute();
$stmt->bind_result($tbl_name);
$stmt->fetch();
if ($stmt1 = $db->prepare("SELECT Name,Address,Phone,Email,Location,Time,Website,Photo1,Date_Published,Rating FROM $tbl_name where categories_ID=?")) {
$cat1 = $_GET['cat'];
$stmt1->bind_param("i", $cat1);
$stmt1->execute();
$stmt1->bind_result($Name, $Address, $Phone, $Email, $Location, $Time, $Website, $Photo1, $Date_Published, $Rating);
$stmt1->fetch();
?>
<div id="loop_listing_taxonomy" class="list" >
<div class="post listing-11323 ">
<img src="images/<?php echo $Photo1; ?>" alt="" title="" />
<div class="entry">
<!--start post type title -->
<div class="listing-title">
<h2 itemprop="name" class="entry-title"><?php echo $Name; ?></h2>
<div class="listing_rating">
<div class="directory_rating_row"><span class="single_rating">
<?php
for ($x = 1; $x <= $Rating; $x++) {
echo '<img src="images/rating-on.png" alt="" />';
}
?>
</span></div>
</div>
<p class="phone"><?php echo $Phone; ?></p><p class="address"><?php echo $Address; echo $Location; ?></p><p class="time"><?php echo $Time; ?></p>
</div>
</div>
</div>
</div>
<?php
$stmt1->close();
}
$stmt->close();
}
?>
答案 0 :(得分:0)
你不能嵌套mysqli prepare语句......我认为你的意思是为第二个查询设置一个while语句...
尝试这样的事情:
<?php
include ("masterzone/php/mysqli.php");
if ($stmt = $db->prepare("SELECT tbl_name FROM listing_title where listing_title_ID=?")) {
$tpe = $_GET['type'];
$stmt->bind_param("i", $tpe);
$stmt->execute();
$stmt->bind_result($tbl_name);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
if ($stmt1 = $db->prepare("SELECT Name,Address,Phone,Email,Location,Time,Website,Photo1,Date_Published,Rating FROM $tbl_name where categories_ID=?")) {
$cat1 = $_GET['cat'];
$stmt1->bind_param("i", $cat1);
$stmt1->execute();
$stmt1->bind_result($Name, $Address, $Phone, $Email, $Location, $Time, $Website, $Photo1, $Date_Published, $Rating);
while($stmt1->fetch()){
?>
<div id="loop_listing_taxonomy" class="list" >
<div class="post listing-11323 ">
<img src="images/<?php echo $Photo1; ?>" alt="" title="" />
<div class="entry">
<!--start post type title -->
<div class="listing-title">
<h2 itemprop="name" class="entry-title"><?php echo $Name; ?></h2>
<div class="listing_rating">
<div class="directory_rating_row"><span class="single_rating">
<?php
for ($x = 1; $x <= $Rating; $x++) {
echo '<img src="images/rating-on.png" alt="" />';
}
?>
</span></div>
</div>
<p class="phone"><?php echo $Phone; ?></p><p class="address"><?php echo $Address; echo $Location; ?></p><p class="time"><?php echo $Time; ?></p>
</div>
</div>
</div>
</div>
<?php
}
$stmt1->free_result();
$stmt1->close();
}
}
?>