2017-11-16 17 views
1

最初のカラムを除いてほとんどすべてが正常に動作していますが、データの前に "1"があります。私はmysqlデータベースからhtmlテーブルにデータを取得しようとしています

私の出力は次のとおりです。
最初の列、すなわち強度に1が付いています。私のデータベースのデータはただ1桁の数字です。

The first column,ie,strength is preceded with 1. The data in my database is just a single digit number.

<?php 
 
    include 'index.php'; 
 
    $sql = "SELECT t.strength, t.timeslot, t.cust_phno , c.fname, c.lname FROM tables t,customer c WHERE t.cust_phno = c.cust_phno"; 
 
    $result = mysqli_query($con,$sql); 
 
    ?> 
 
    
 
    <div id="view"> 
 
    <table style="width:90%"> 
 
     <thead> 
 
     <tr> 
 

 
     <th> Table Strength </th> 
 
     <th> Time Slot </th> 
 
     <th> Customer Phone Number</th> 
 
     <th> Customer Name </th> 
 
     </tr> 
 
    </thead> 
 
    <tbody> 
 
     <?php 
 
     while($array = mysqli_fetch_assoc($result)) { 
 
     echo 
 
     print "<tr> <td>"; 
 
     echo $array["strength"]; 
 
     print "</td> <td>"; 
 
     echo $array["timeslot"]; 
 

 
     print "</td> <td>"; 
 
     echo $array["cust_phno"]; 
 
     print "</td> <td>"; 
 
     echo $array["fname"]; 
 
     print "&nbsp"; 
 
     echo $array["lname"]; 
 

 

 
     print "</td> </tr>"; 
 

 

 
      } 
 
     ?> 
 

 

 
    </tbody> 
 
    </table>

+0

は印刷されませエコー。 –

答えて

5

1 .. ...次の行が若干異なることが必要

while($array = mysqli_fetch_assoc($result)) { 
    echo 
    print "<tr> <td>"; 

printからの復帰をエコーの結果でありますエコーを必要としません。

while($array = mysqli_fetch_assoc($result)) { 
    print "<tr> <td>"; 
+0

ありがとうございました!出来た!! –

+0

助けてくれてうれしい、これを受け入れられた答え(あなたがそれに満足すれば)としてマークすることができれば、それは物事をクリアするだろう。お返事ありがとうございます。 –

0
<?php 
     while($array = mysqli_fetch_assoc($result)) { 
     print "<tr> <td>"; 
     echo $array["strength"]; 
     print "</td> <td>"; 
     echo $array["timeslot"]; 

     print "</td> <td>"; 
     echo $array["cust_phno"]; 
     print "</td> <td>"; 
     echo $array["fname"]; 
     print "&nbsp"; 
     echo $array["lname"]; 


     print "</td> </tr>"; 


      } 
     ?> 

コードからechoを削除します。

+0

ありがとうございました!出来た! –

0

シンプルで簡単なプロセスですので、例とソースコードとして説明します。

まず、PHPでmysqliを使用してデータベースを接続します。このコードを使うと、$ con = mysqli_connect( 'localhost'、 'root'、 'password'、 'Database Name');

PHPのMySQLテーブルからmysqliを使用してすべてのデータを選択します。選択したレコードに対してMySQLクエリを使用している場合や、PHPプロジェクトでレコードを取得している場合は、簡単に使用できます。 whileループを使用してテーブルページに結果を取得します。ここ

<?php 
 
include "db_connect.php"; 
 
?> 
 
<table class="table"> 
 
\t <thead class="thead-inverse"> 
 
\t <tr> 
 
\t \t <th>#</th> 
 
\t \t <th>Name</th> 
 
\t \t <th>Email</th> 
 
\t \t <th>Phone</th> 
 
\t \t <th>Address</th> 
 
\t </tr> 
 
\t </thead> 
 
\t <tbody> 
 
\t <?php 
 
\t $i=1; 
 
\t $mysqli_qry=mysqli_query($con,"SELECT * from `Table Name` ORDER BY `id` DESC"); 
 
\t while($row=mysqli_fetch_array($mysqli_qry)) 
 
\t { 
 
\t ?> 
 
\t <tr> 
 
\t \t <th scope="row"><?php echo $i; ?></th> 
 
\t \t <td><?php echo $row['1']; ?></td> 
 
\t \t <td><?php echo $row['3']; ?></td> 
 
\t \t <td><?php echo $row['2']; ?></td> 
 
\t \t <td><?php echo $row['4']; ?></td> 
 
\t </tr> 
 
\t <?php $i++; } ?> 
 
\t </tbody> 
 
</table>

詳細表示:それは本当の1を与えるので、あなただけ使用する必要がselect record and fetch result in PHP using mysqli in PHP

関連する問題