我的代码将所有数据输出到1行中,如何使其将单独的数据输出到单独的行中?

时间:2019-04-10 17:29:13

标签: php mysql

当我的数据从服务器输出到网站时,它将输出到第一行,而不是向下一行然后输出下一行数据 !

output


session_start();
$view = new stdClass();
$view->pageTitle = 'Camp Sites';
require_once('views/CampSites.phtml');
require_once('Models/campData.php');
require_once('Models/campDataSet.php');

$campDataSet = new campDataSet();


if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $search = $_POST['search'];
    $_SESSION['search'] = $search;

    $sqlQuery = "SELECT * FROM campsites ='$search'";
    $result = $campDataSet->fetchAllCamps($sqlQuery);

    if (count($result) > 0) {
        echo'<div class="table-responsive">
                <table class="table">
                    <thead id="table1Head">
                    <tr><td>campID</td>
                        <td>Name</td>
                        <td>Address</td>
                        <td>Postcode</td>
                        <td>Country</td>
                        <td>Latitude</td>
                        <td>Longitude</td>
                        <td>email</td>
                        <td>Phone<td></tr>
                    </thead>
                    <tbody>

            </div>';
        foreach ($result as $row) {
            echo '<td>' . $row->id_campsite. '</td> <td>' . $row->campsite_name . '</td> <td>' . $row->address . '</td> <td>' . $row->postcode . '</td> <td>' . $row->country. '</td> <td>' . $row->lattitude . '</td> <td>' . $row->longitude . '</td> <td>' . $row->email . '</td> <td>' . $row->phone_number . '</td> </td>';
        }
        echo "</tbody></table>";
    } else {
        print " 0 results";
    }
}


1 个答案:

答案 0 :(得分:2)

if (count($result) > 0) {
echo'<div class="table-responsive">
                <table class="table">
                    <thead id="table1Head">
                    <tr><td>campID</td>
                        <td>Name</td>
                        <td>Address</td>
                        <td>Postcode</td>
                        <td>Country</td>
                        <td>Latitude</td>
                        <td>Longitude</td>
                        <td>email</td>
                        <td>Phone<td></tr>
                   </thead>
                    <tbody>

            </div>';
foreach ($result as $row) {
echo '<tr><td>' . $row->id_campsite. '</td> <td>' . $row->campsite_name . '</td> <td>' . $row->address . '</td> <td>' . $row->postcode . '</td> <td>' . $row->country. '</td> <td>' . $row->lattitude . '</td> <td>' . $row->longitude . '</td> <td>' . $row->email . '</td> <td>' . $row->phone_number . '</td> </td></tr>';
}
echo "</tbody></table>";
} else {
    print " 0 results";
}

您需要像上面那样在您的foreach中的代码周围包装标签。