无法从数据库中检索数据

时间:2021-10-07 09:10:38

I have some data in my database table and when I am trying to fetch it and display using mysqli_fetch_assoc() and display them on a web page I am failing can some one please help me knowing where I am doing it wrong.

我在我的数据库表中有一些数据,当我尝试获取它并使用mysqli_fetch_assoc()显示并在网页上显示我失败时可以请一些人帮我知道我在哪里做错了。

my table(saloon) consists columns:

我的桌子(沙龙)由列组成:

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

and this is the code

这是代码

<?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]

p2

2 个解决方案

#1


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']?>

change it

<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'];?>

#2


0  

If you want to use conditional mysqli_fetch_assoc or mysqli_fetch_array, you will have to have your codes you want to print to be kept inside the braket of the condition. You are doing it wrong as you only retrieve, print it and close it.

如果要使用条件mysqli_fetch_assoc或mysqli_fetch_array,则必须将要打印的代码保存在条件的范围内。你做错了,因为你只检索,打印并关闭它。

  while ($row=mysqli_fetch_array($query))
             {      echo  $row['saloon_name'];} 

This is what I will always do when typing it.

这是我在输入时总是会做的。

 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
           ?>

You could do it in the way you're doing by retrieving and saving it into meaningful variable:

您可以通过检索并将其保存到有意义的变量中来执行此操作:

   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
 ?>

Hope it solve your problem.

希望它能解决你的问题。

#1


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']?>

change it

<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'];?>

#2


0  

If you want to use conditional mysqli_fetch_assoc or mysqli_fetch_array, you will have to have your codes you want to print to be kept inside the braket of the condition. You are doing it wrong as you only retrieve, print it and close it.

如果要使用条件mysqli_fetch_assoc或mysqli_fetch_array,则必须将要打印的代码保存在条件的范围内。你做错了,因为你只检索,打印并关闭它。

  while ($row=mysqli_fetch_array($query))
             {      echo  $row['saloon_name'];} 

This is what I will always do when typing it.

这是我在输入时总是会做的。

 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
           ?>

You could do it in the way you're doing by retrieving and saving it into meaningful variable:

您可以通过检索并将其保存到有意义的变量中来执行此操作:

   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
 ?>

Hope it solve your problem.

希望它能解决你的问题。