Php SQL格式化表数据

Php SQL格式化表数据,php,sql,Php,Sql,我有一个select查询,它从数据库中提取所有数据,但它是这样显示的: First name: Jasmine Last name: Santiago Address: 123 Butt street City: Butt hill Customer ID: 12 我试图让它像这样显示: First name: Last name: Address: City: Customer ID: Jasmine Santiago 123 Butt

我有一个select查询,它从数据库中提取所有数据,但它是这样显示的:

First name: Jasmine
Last name: Santiago
Address: 123 Butt street
City: Butt hill
Customer ID: 12
我试图让它像这样显示:

First name:   Last name:  Address:          City:       Customer ID:
Jasmine       Santiago    123 Butt street   Butt hill   12
with          more        rows              here of just the data not the labels
<?php 
if(isset($_POST["get-user-info"])) {
$user_info_sql = "SELECT * from customer_info";
$user_info_result = $conn->query($user_info_sql);

if ($user_info_result->num_rows > 0) {
  echo "<tr><th>First name: </th><th>Last name:</th><th>Address:</th><th>City:</th><th>Customer ID:</th></tr>";
    while($row = mysqli_fetch_assoc($user_info_result)) {
        echo "<tr><td>". $row["First_name"]."</td><td>" . $row["Last_name"] . "</td><td>" . $row["Address"]. "<td></td>" . $row["City"] . "<td></td>" . $row["Customer_id"] . "</td></tr>";
    } 
} else {
    echo "No results found";
} 
}
但我有不止一行的数据…所以我不确定我错在哪里。这是我的询问和回应声明

if(isset($_POST["get-user-info"])) {
    $user_info_sql = "SELECT * from customer_info";
    $user_info_result = $conn->query($user_info_sql);

    if ($user_info_result->num_rows > 0) {
        while($row = mysqli_fetch_assoc($user_info_result)) {
            echo "<tr><th>First name: </th>" . $row["First_name"]. "</tr></br>" . "<tr>Last name: " . $row["Last_name"] . "</tr></br>" . "<tr>Address: " . $row["Address"]. "</tr></br> " . "<tr>City: " . $row["City"] . "</tr></br>" . "Customer ID: " . $row["Customer_id"] . "</br>" . "</br></br>";
        } 
    } else {
        echo "No results found";
    } 
}
if(isset($\u POST[“获取用户信息”])){
$user\u info\u sql=“从客户信息中选择*”;
$user\u info\u result=$conn->query($user\u info\u sql);
如果($user\u info\u result->num\u rows>0){
while($row=mysqli\u fetch\u assoc($user\u info\u result)){
呼应“名字:.$row[“First_name”]。”
“.$row[“Last_name”]。”
“地址:.$row[“Address”]。”
“城市:.$row[“City”]。“
”“客户ID:.$row[“客户ID”]。“

”; } }否则{ 回显“未找到结果”; } }
正如你所看到的,我开始做tr/th/td,但我迷路了……我想也许我需要呼应一下……之类的一切

回音台 回音tr 回声
…但我在这里迷路了,因为这会再次回显标签…

尝试以下方法:

First name:   Last name:  Address:          City:       Customer ID:
Jasmine       Santiago    123 Butt street   Butt hill   12
with          more        rows              here of just the data not the labels
<?php 
if(isset($_POST["get-user-info"])) {
$user_info_sql = "SELECT * from customer_info";
$user_info_result = $conn->query($user_info_sql);

if ($user_info_result->num_rows > 0) {
  echo "<tr><th>First name: </th><th>Last name:</th><th>Address:</th><th>City:</th><th>Customer ID:</th></tr>";
    while($row = mysqli_fetch_assoc($user_info_result)) {
        echo "<tr><td>". $row["First_name"]."</td><td>" . $row["Last_name"] . "</td><td>" . $row["Address"]. "<td></td>" . $row["City"] . "<td></td>" . $row["Customer_id"] . "</td></tr>";
    } 
} else {
    echo "No results found";
} 
}

尝试以下方法:

First name:   Last name:  Address:          City:       Customer ID:
Jasmine       Santiago    123 Butt street   Butt hill   12
with          more        rows              here of just the data not the labels
<?php 
if(isset($_POST["get-user-info"])) {
$user_info_sql = "SELECT * from customer_info";
$user_info_result = $conn->query($user_info_sql);

if ($user_info_result->num_rows > 0) {
  echo "<tr><th>First name: </th><th>Last name:</th><th>Address:</th><th>City:</th><th>Customer ID:</th></tr>";
    while($row = mysqli_fetch_assoc($user_info_result)) {
        echo "<tr><td>". $row["First_name"]."</td><td>" . $row["Last_name"] . "</td><td>" . $row["Address"]. "<td></td>" . $row["City"] . "<td></td>" . $row["Customer_id"] . "</td></tr>";
    } 
} else {
    echo "No results found";
} 
}

您应该只显示一次标题:

if ($user_info_result->num_rows > 0) {
    // display table header
    echo "<table><tr><th>First name: </th><th>Last name: </th><th>Address: </th><th>City: </th><th>Customer ID: </th></tr>";
    while($row = mysqli_fetch_assoc($user_info_result)) {
        echo "<tr><td>". $row["First_name"]. "</td>" .
             "<td>". $row["Last_name"]. "</td>" .
             "<td>". $row["Address"]. "</td>" .
             "<td>". $row["City"]. "</td>" .
             "<td>". $row["Customer_id"]. "</td></tr>";
    }
    echo "</table>";
}
if($user\u info\u result->num\u rows>0){
//显示表格标题
echo“名字:姓氏:地址:城市:客户ID:”;
while($row=mysqli\u fetch\u assoc($user\u info\u result)){
回显“$row[“First_name”]”。
“.$row[“姓氏”]”。
“.$行[“地址”]”。
“.$row[“City”]”。
“.$row[“客户id”]”;
}
回声“;
}

您应该只显示一次标题:

if ($user_info_result->num_rows > 0) {
    // display table header
    echo "<table><tr><th>First name: </th><th>Last name: </th><th>Address: </th><th>City: </th><th>Customer ID: </th></tr>";
    while($row = mysqli_fetch_assoc($user_info_result)) {
        echo "<tr><td>". $row["First_name"]. "</td>" .
             "<td>". $row["Last_name"]. "</td>" .
             "<td>". $row["Address"]. "</td>" .
             "<td>". $row["City"]. "</td>" .
             "<td>". $row["Customer_id"]. "</td></tr>";
    }
    echo "</table>";
}
if($user\u info\u result->num\u rows>0){
//显示表格标题
echo“名字:姓氏:地址:城市:客户ID:”;
while($row=mysqli\u fetch\u assoc($user\u info\u result)){
回显“$row[“First_name”]”。
“.$row[“姓氏”]”。
“.$行[“地址”]”。
“.$row[“City”]”。
“.$row[“客户id”]”;
}
回声“;
}

谢谢,老兄,我之前尝试过类似的方法,但没有成功。我只是在重复每一行,而不是将其串联起来。谢谢,我之前尝试过类似的方法,但没有成功。我只是在重复每一行,而不是把它连在一起。