簡體   English   中英

無法從數據庫中檢索數據

[英]Unable to retrieve data from database

我的數據庫表中有一些數據,當我嘗試獲取它並使用mysqli_fetch_assoc()顯示並在網頁上顯示它們時,我失敗了,有人可以幫助我知道我在哪里做錯了。

我的桌子(轎車)由列組成:

saloon_sex

沙龍_地圖

轎車價格

沙龍名稱

沙龍號碼

沙龍圖片

沙龍位置

沙龍哦

Saloon_oh1

沙龍_服務

沙龍_menu1

Saloon_menu2

Saloon_menu3

沙龍_照片1

沙龍_照片2

沙龍_photo3

沙龍區

這是代碼

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

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

如果要使用條件mysqli_fetch_assocmysqli_fetch_array ,則必須將要打印的代碼保存在條件的mysqli_fetch_assoc內。 你做錯了,因為你只檢索、打印並關閉它。

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

希望它能解決你的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM