我试图在while
回音中回显我的PHP html
循环。
基本上,我想在另一个回声中回声。这可能吗?
这是我的代码:
<?php
session_start();
require 'config.php';
if (@$_SESSION['username']) {
$query = "SELECT * FROM `crew_info`";
$query_run = mysqli_query($conn,$query);
echo '<!DOCTYPE html>
<html>
<head>
<title>All Crew</title>
</head>
<body>
<table>
<tr>
<th>First Name: </th>
<th>Middle Name: </th>
<th>Last Name: </th>
<th>Age: </th>
<th>Birth Date: </th>
<th>Birth Place: </th>
<th>Gender: </th>
<th>Martial Status: </th>
<th>Nationality: </th>
<th>Email Address: </th>
<th>Address 1: </th>
<th>Address 2: </th>
<th>Course: </th>
<th>School Graduated: </th>
<th>Remarks: </th>
<th>Date Added: </th>
<th>Status: </th>
</tr>
<tr>
while($record = mysqli_fetch_assoc($query_run)) {
echo "<tr>";
echo "<th>".$record['first_name']."</th>";
echo "<th>".$record['middle_name']."</th>";
echo "<th>".$record['last_name']."</th>";
echo "<th>".$record['age']."</th>";
echo "<th>".$record['birth_date']."</th>";
echo "<th>".$record['birth_place']."</th>";
echo "<th>".$record['gender']."</th>";
echo "<th>".$record['martial_status']."</th>";
echo "<th>".$record['nationality']."</th>";
echo "<th>".$record['email_address']."</th>";
echo "<th>".$record['address_1']."</th>";
echo "<th>".$record['address_2']."</th>";
echo "<th>".$record['course']."</th>";
echo "<th>".$record['school_graduated']."</th>";
echo "<th>".$record['remarks']."</th>";
echo "<th>".$record['date_added']."</th>";
echo "<th>".$record['crew_status']."</th>";
echo "</tr><br>";
</tr>
</table>
</body>
</html>';
}
}
else {
header('Location: /practice1/index.php');
}
?>
我希望有人可以帮助我
答案 0 :(得分:2)
将您的代码更改为:
echo '<!DOCTYPE html>
<html>
<head>
<title>All Crew</title>
</head>
<body>
<table>
<tr>
<th>First Name: </th>
<th>Middle Name: </th>
<th>Last Name: </th>
<th>Age: </th>
<th>Birth Date: </th>
<th>Birth Place: </th>
<th>Gender: </th>
<th>Martial Status: </th>
<th>Nationality: </th>
<th>Email Address: </th>
<th>Address 1: </th>
<th>Address 2: </th>
<th>Course: </th>
<th>School Graduated: </th>
<th>Remarks: </th>
<th>Date Added: </th>
<th>Status: </th>
</tr>
<tr>';
while($record = mysqli_fetch_assoc($query_run)) {
echo "<tr>";
echo "<th>".$record['first_name']."</th>";
echo "<th>".$record['middle_name']."</th>";
echo "<th>".$record['last_name']."</th>";
echo "<th>".$record['age']."</th>";
echo "<th>".$record['birth_date']."</th>";
echo "<th>".$record['birth_place']."</th>";
echo "<th>".$record['gender']."</th>";
echo "<th>".$record['martial_status']."</th>";
echo "<th>".$record['nationality']."</th>";
echo "<th>".$record['email_address']."</th>";
echo "<th>".$record['address_1']."</th>";
echo "<th>".$record['address_2']."</th>";
echo "<th>".$record['course']."</th>";
echo "<th>".$record['school_graduated']."</th>";
echo "<th>".$record['remarks']."</th>";
echo "<th>".$record['date_added']."</th>";
echo "<th>".$record['crew_status']."</th>";
echo '</tr>';
}
echo '</table>
</body>
</html>';
答案 1 :(得分:0)
回声中没有回声...
不
echo ' aaa echo "bbbb"; ccccc ';
可是:
echo ' aaa ';
echo "bbbb";
echo 'ccccc ';
所以你的代码看起来会是:
echo '<!DOCTYPE html>
<html>
<head>
<title>All Crew</title>
</head>
<body>
<table>
<tr>
<th>First Name: </th>
<th>Middle Name: </th>
<th>Last Name: </th>
<th>Age: </th>
<th>Birth Date: </th>
<th>Birth Place: </th>
<th>Gender: </th>
<th>Martial Status: </th>
<th>Nationality: </th>
<th>Email Address: </th>
<th>Address 1: </th>
<th>Address 2: </th>
<th>Course: </th>
<th>School Graduated: </th>
<th>Remarks: </th>
<th>Date Added: </th>
<th>Status: </th>
</tr>
<tr>';
while($record = mysqli_fetch_assoc($query_run)) {
echo "<tr>";
echo "<th>".$record['first_name']."</th>";
echo "<th>".$record['middle_name']."</th>";
echo "<th>".$record['last_name']."</th>";
echo "<th>".$record['age']."</th>";
echo "<th>".$record['birth_date']."</th>";
echo "<th>".$record['birth_place']."</th>";
echo "<th>".$record['gender']."</th>";
echo "<th>".$record['martial_status']."</th>";
echo "<th>".$record['nationality']."</th>";
echo "<th>".$record['email_address']."</th>";
echo "<th>".$record['address_1']."</th>";
echo "<th>".$record['address_2']."</th>";
echo "<th>".$record['course']."</th>";
echo "<th>".$record['school_graduated']."</th>";
echo "<th>".$record['remarks']."</th>";
echo "<th>".$record['date_added']."</th>";
echo "<th>".$record['crew_status']."</th>";
echo '</tr>';
}
echo '</table>
</body>
</html>';
答案 2 :(得分:0)
或类似于:(注意; while环上方的tr也必须删除,因为while循环中已有一个。
<?php
$loop = "";
while ($record = mysqli_fetch_assoc($query_run)) {
$loop .= "<tr>";
$loop .= "<th>" . $record['first_name'] . "</th>";
$loop .= "<th>" . $record['middle_name'] . "</th>";
$loop .= "<th>" . $record['last_name'] . "</th>";
$loop .= "<th>" . $record['age'] . "</th>";
$loop .= "<th>" . $record['birth_date'] . "</th>";
$loop .= "<th>" . $record['birth_place'] . "</th>";
$loop .= "<th>" . $record['gender'] . "</th>";
$loop .= "<th>" . $record['martial_status'] . "</th>";
$loop .= "<th>" . $record['nationality'] . "</th>";
$loop .= "<th>" . $record['email_address'] . "</th>";
$loop .= "<th>" . $record['address_1'] . "</th>";
$loop .= "<th>" . $record['address_2'] . "</th>";
$loop .= "<th>" . $record['course'] . "</th>";
$loop .= "<th>" . $record['school_graduated'] . "</th>";
$loop .= "<th>" . $record['remarks'] . "</th>";
$loop .= "<th>" . $record['date_added'] . "</th>";
$loop .= "<th>" . $record['crew_status'] . "</th>";
$loop .= '</tr>';
}
$out = '<!DOCTYPE html>
<html>
<head>
<title>All Crew</title>
</head>
<body>
<table>
<tr>
<th>First Name: </th>
<th>Middle Name: </th>
<th>Last Name: </th>
<th>Age: </th>
<th>Birth Date: </th>
<th>Birth Place: </th>
<th>Gender: </th>
<th>Martial Status: </th>
<th>Nationality: </th>
<th>Email Address: </th>
<th>Address 1: </th>
<th>Address 2: </th>
<th>Course: </th>
<th>School Graduated: </th>
<th>Remarks: </th>
<th>Date Added: </th>
<th>Status: </th>
</tr>';
echo $out . $loop . '</table>
</body>
</html>';