gpt4 book ai didi

php - 在特定区域适配 HTML 表格

转载 作者:太空宇宙 更新时间:2023-11-03 19:26:42 25 4
gpt4 key购买 nike

我正在构建一个 HTML 表格,该表格显示来自 MySQL 数据库的信息,并具有更新或删除数据库中的行的功能。

这是我当时的代码:

<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Program</th>
<th>Class</th>
<th>Start Date</th>
<th>End Date</th>
<th>Country</th>
</tr>

<?php

$db = JFactory::getDBO();

$query = "SELECT * FROM student_management_module";

$db->setQuery($query);
$rows = $db->loadObjectList();

foreach ($rows as &$row) {
echo "<form action=index.php/component/studentmanagement/?task=update method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=fname id=name_val value=" .$row->name. " </td>";
echo "<td>" . "<input type=text name=email id=email_val value=" .$row->email. " </td>";
echo "<td>" . "<input type=text name=prog id=prog_val value=" .$row->program. " </td>";
echo "<td>" . "<input type=text name=class id=class_val value=" .$row->class. " </td>";
echo "<td>" . "<input type=text name=sdate id=start_val value=" .$row->start_date. " </td>";
echo "<td>" . "<input type=text name=edate id=end_val value=" .$row->end_date. " </td>";
echo "<td>" . "<input type=text name=country id=country_val value=" .$row->country. " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" .$row->student_id. " </td>";
echo "<td>" . "<input type=submit name=update value=update". " </td>";
echo "<td>" . "<input type=submit name=delete value=delete". " </td>";
echo "</tr>";
echo "</form>";
}

?>

这是当前表格的样子:

Picture of table

但是栏目太多,装不下我想要的空间。

如何在底部创建一个水平滚动条并确保更新和删除按钮与该滚动条分开,以便更新和插入按钮始终显示在右侧。

我试过 CSS overflow 属性,但它包括滚动中的插入和删除。

如有任何帮助,我们将不胜感激,并提前致谢。

最佳答案

首先,你忘了关闭input标签:

echo "<td>" . "<input type=text name=fname id=name_val value=" .$row->name. "> </td>";
//-----------------------------------------------------------Here------------^

其次,您忘记了标签中的'':

echo "<td>" . "<input type='text' name='fname' id='name_val' value='" .$row->name. "'> </td>";

第三,如果你想要一个水平滚动条,你应该看起来像这样:

        html{
max-width: 100%;
overflow-x: hidden;
}

.headcol {
position: absolute;
width: 120px;
left: 0;
top: auto;
border-top-width: 1px;
/*only relevant for first row*/
margin-top: -1px;
/*compensate for top border*/
}

.div {
width: 86%;
overflow-x: scroll;
margin-left: 5em;
overflow-y: visible;
padding: 0;
}
 <html>
<div class="div">
<table style="width: 100%; overflow-x: auto">
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
<th>Program</th>
<th>Class</th>
<th>Student ID</th>
<th>Start Date</th>
<th>End Date</th>
<th>Country</th>
</tr>
<tr>
<form>
<td class="headcol"><input type="submit" name="update" value="update"><input type="submit" name="delete" value="delete"></td>

<td><input type="text" name="fname" id="name_val" value=" .$row->name. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->mail. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Program. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Class. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StudentID. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StartDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->EndDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Country. "></td>
</form>
</tr>
<tr>
<form>
<td class="headcol"><input type="submit" name="update" value="update"><input type="submit" name="delete" value="delete"></td>

<td><input type="text" name="fname" id="name_val" value=" .$row->name. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->mail. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Program. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Class. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StudentID. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StartDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->EndDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Country. "></td>
</form>
</tr>
<tr>
<form>
<td class="headcol"><input type="submit" name="update" value="update"><input type="submit" name="delete" value="delete"></td>

<td><input type="text" name="fname" id="name_val" value=" .$row->name. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->mail. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Program. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Class. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StudentID. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StartDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->EndDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Country. "></td>
</form>
</tr>
<tr>
<form>
<td class="headcol"><input type="submit" name="update" value="update"><input type="submit" name="delete" value="delete"></td>

<td><input type="text" name="fname" id="name_val" value=" .$row->name. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->mail. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Program. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Class. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StudentID. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StartDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->EndDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Country. "></td>
</form>
</tr>
<tr>
<form>
<td class="headcol"><input type="submit" name="update" value="update"><input type="submit" name="delete" value="delete"></td>

<td><input type="text" name="fname" id="name_val" value=" .$row->name. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->mail. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Program. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Class. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StudentID. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StartDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->EndDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Country. "></td>
</form>
</tr>
<tr>
<form>
<td class="headcol"><input type="submit" name="update" value="update"><input type="submit" name="delete" value="delete"></td>

<td><input type="text" name="fname" id="name_val" value=" .$row->name. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->mail. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Program. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Class. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StudentID. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StartDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->EndDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Country. "></td>
</form>
</tr>
<tr>
<form>
<td class="headcol"><input type="submit" name="update" value="update"><input type="submit" name="delete" value="delete"></td>

<td><input type="text" name="fname" id="name_val" value=" .$row->name. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->mail. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Program. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Class. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StudentID. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->StartDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->EndDate. "></td>
<td><input type="text" name="fname" id="name_val" value=" .$row->Country. "></td>
</form>
</tr>

</table>
</div>
</html>

关于php - 在特定区域适配 HTML 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51126166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com