我的数据库表中有一些数据,当我尝试获取它并使用mysqli_fetch_assoc()
显示并在网页上显示我失败时可以请一些人帮我知道我在做错了
我的桌子(沙龙)包括栏目:
saloon_sex
saloon_map
saloon_price
saloon_name
saloon_number
saloon_image
saloon_location
saloon_oh
saloon_oh1
saloon_services
saloon_menu1
saloon_menu2
saloon_menu3
saloon_photo1
saloon_photo2
saloon_photo3
saloon_area
这是代码
<?php
$connection = mysqli_connect('localhost','root','') or die(mysqli_error($connection));
mysqli_select_db($connection,'cmssite') or die (mysqli_error($connection));
if($connection){
echo('connected to database');
}
if(isset($_POST['submit'])) {
if(isset($_POST['area'])) {
$search_value = $_POST['area'];
$query = mysqli_query( $connection,"select * from saloon where saloon_area LIKE '%$search_value%'");
if(! $query )
{
die('Could not get data: ' . mysqli_error($query));
}
$row=null;
// $row=mysqli_fetch_assoc($query);
while ($row=mysqli_fetch_array($query))
{ echo $row['saloon_name'];}
?>
<div class="row">
<div class="col-md-4">
<img src="images/toni&guysalon.jpg" height="150" width="150"/></a>
</div>
<div class="col-md-5">
<h3 style="font-weight:bold; margin-top:10px;"><?php echo $row['saloon_name']?></h3>
<img src="images/unisex.png" width="15" height="15"> <?php echo $row['saloon_sex']?>
<div class="clearfix" style="height:10px;"></div>
<img src="images/location.png" width="15" height="15"> Opposite Nerus Emporio, Madhapur
<div class="clearfix" style="height:10px;"></div>
<img src="images/rupee.png" width="15" height="15"> 400+ For Haircut
<div class="clearfix" style="height:10px;"></div>
<img src="images/time.png" width="15" height="15"> Mon to Sun - 10:00 AM to 09:30 PM
</div>
</div>
<?php } }
?>
[p1][1]
答案 0 :(得分:0)
<h3 style="font-weight:bold; margin-top:10px;"><?php echo $row['saloon_name']?></h3>
<img src="images/unisex.png" width="15" height="15"> <?php echo $row['saloon_sex']?>
改变它
<h3 style="font-weight:bold; margin-top:10px;"><?php echo $row['saloon_name'];?></h3>
<img src="images/unisex.png" width="15" height="15"> <?php echo $row['saloon_sex'];?>
答案 1 :(得分:0)
如果您想使用条件mysqli_fetch_assoc
或mysqli_fetch_array
,您必须将要打印的代码保留在条件的范围内。
你做错了,因为你只需要检索,打印并关闭它。
while ($row=mysqli_fetch_array($query))
{ echo $row['saloon_name'];}
这是我在输入时总是会做的。
while ($row = mysqli_fetch_assoc($query)) {
<div class="col-md-5">
<h3 style="font-weight:bold; margin-top:10px;"><?php echo $row['saloon_name']?></h3>
<img src="images/unisex.png" width="15" height="15"> <?php echo $row['saloon_sex']?>
<div class="clearfix" style="height:10px;"></div>
<img src="images/location.png" width="15" height="15"> Opposite Nerus Emporio, Madhapur
<div class="clearfix" style="height:10px;"></div>
<img src="images/rupee.png" width="15" height="15"> 400+ For Haircut
<div class="clearfix" style="height:10px;"></div>
<img src="images/time.png" width="15" height="15"> Mon to Sun - 10:00 AM to 09:30 PM
</div>
<?php
} // closing tag for mysqli_fetch_assoc/array
?>
您可以通过检索并将其保存到有意义的变量中来执行此操作:
while($row = mysqli_fetch_assoc($query)) {
$saloonSex = $row['saloon_sex'];
$saloonPrice = $row['saloon_price'];
$saloonName = $row['saloon_name'];
... etc etc
<div class="col-md-5">
<h3 style="font-weight:bold; margin-top:10px;"><?php echo $saloonName?></h3>
<img src="images/unisex.png" width="15" height="15"> <?php echo $saloonSex?>
.....etc etc
<?php
} // closing tag for mysqli_fetch_assoc/array
?>
希望它能解决你的问题。