我试图将firstname和lastname行放在一行中。 这是我到目前为止的代码,
$sql = "SELECT firstname, lastname, phone, department FROM tl_member ORDER BY firstname LIMIT 29";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><br><hr><th align='left'>Naam</th><th align='left'>telefoon<th align='left'>phone</th><th>afdeling</tr>";
// output data in rows
while($row = $result->fetch_assoc()) {
echo "<tr><td>" .$row["firstname"]."</td><td>" .$row["lastname"]."</td><td>" .$row["phone"]."</td><td>" .$row["department"]."</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
firstname和lastname现在单独显示我希望他们一起合作?
答案 0 :(得分:0)
我认为你的意思是:
$sql = "SELECT firstname, lastname, phone, department FROM tl_member ORDER BY firstname LIMIT 29";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><br><hr><th align='left'>Naam</th><th align='left'>telefoon<th align='left'>phone</th><th>afdeling</tr>";
// output data in rows
while($row = $result->fetch_assoc()) {
echo "<tr><td>" .$row["firstname"]." " .$row["lastname"]."</td><td>" .$row["phone"]."</td><td>" .$row["department"]."</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
答案 1 :(得分:0)
Huum ..
那样的?
$sql = "SELECT firstname, lastname, phone, department FROM tl_member ORDER BY firstname LIMIT 29";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><br><hr><th align='left'>Naam</th><th align='left'>telefoon<th align='left'>phone</th><th>afdeling</tr>";
// output data in rows
while($row = $result->fetch_assoc()) {
echo "<tr><td>" .$row["firstname"]." ".$row["lastname"]."</td><td>" .$row["phone"]."</td><td>" .$row["department"]."</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
答案 2 :(得分:0)
我相信你的意思是在同一行/细胞中?喜欢这个?
while($row = $result->fetch_assoc()) {
echo "<tr><td>" .$row["firstname"] . $row["lastname"]."</td><td>" .$row["phone"]."</td>
<td>".$row["department"]."</tr>";
}
答案 3 :(得分:0)
几乎就在那里!您只需要在同一个td
中放置名字和第二个名字echo "<tr><td>" . $row["firstname"] . " " . $row["lastname"] . "</td><td>" . $row["phone"] . "</td><td>" . $row["department"] . "</tr>";
答案 4 :(得分:0)
以这种方式编写查询:
$sql = "SELECT firstname, lastname, phone, department,concat(firstname,'',lastname) fullname FROM tl_member ORDER BY firstname LIMIT 29";
$result = $conn->query($sql);
要获取全名,您需要使用:$ row [&#34; fullname&#34;]