如何添加标题、复选框和提交/取消按钮以形成php表?
我需要创建一个表单,从csv文件中提取数据,以及代码中的其他类型的数据如何添加标题、复选框和提交/取消按钮以形成php表?,php,html,forms,Php,Html,Forms,我需要创建一个表单,从csv文件中提取数据,以及代码中的其他类型的数据 <html> <body> <table border=1px solid black> <?php $fp=fopen('sample.csv','r'); while(($data=fgetcsv($fp,1000,";"))!==FALSE){ $user=$DB->get_record('user',array('username'=>trim($data
<html>
<body>
<table border=1px solid black>
<?php
$fp=fopen('sample.csv','r');
while(($data=fgetcsv($fp,1000,";"))!==FALSE){
$user=$DB->get_record('user',array('username'=>trim($data[0])));
echo '<tr><td>' . $data[0] . '</td><td>' . $user->firstname . '</td><td>' . $user->lastname . '</td><td>' . array_shift($dataClipNumber) . '</td><td>' . $data[1] .'</td><td>'.whatCourse(array_shift($dataClipCourse)). '</td></tr>';
}
fclose($fp);
?>
</table>
</body>
</html>
以下是到目前为止的输出:
我想为每一列添加标题。我试图将th标记放在tr和td之间,但它显示为另一列。除此之外,我想在所有用户名(firstcolumn)旁边添加复选框,默认情况下它们可以被选中吗?
最后,放置一个提交按钮,保存选中标记的用户名并调用我的注册代码(执行注册的moodle插件)
多谢各位
编辑:它起作用了:)尽管按钮仍然缺失。关于上面有“,”的词。就像照片中的努梅罗。有没有办法在标题中解决这个问题
编辑2:因为我在Moodle上做这件事,我删除了一个变量,它给了它灰色的外观,因为这可能会干扰按钮。但不是。用一个较小的例子:
您需要在迭代之外添加标题
<form id="form">
<table border=1px solid black>
<tr>
<td>#</td>
<td>Column-1</td>
<td>Column-2</td>
<td>Column-3</td>
<td>Column-4</td>
<td>Column-5</td>
<td>Column-6</td>
</tr>
<?php
$fp=fopen('sample.csv','r');
while(($data=fgetcsv($fp,1000,";"))!==FALSE){
$user=$DB->get_record('user',array('username'=>trim($data[0])));
echo '<tr>' .
'<td><input type="checkbox" name="username[]" value="' . $data[0] . '" checked="checked"/></td>' .
'<td>' . $data[0] . '</td><td>' . $user->firstname . '</td>' .
'<td>' . $user->lastname . '</td>' .
'<td>' . array_shift($dataClipNumber) . '</td>' .
'<td>' . $data[1] .'</td>' .
'<td>' . whatCourse(array_shift($dataClipCourse)). '</td>' .
'</tr>';
}
fclose($fp);
?>
</table>
<a href="javascript:;" onclick="document.getElementById('form').submit();">Save</a>
</form>
#
第1列
第2栏
第3栏
第4栏
第5栏
第6栏
编辑:您需要将
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
在“html标题”部分中,修复页面上的特殊字符视图您需要在迭代之外添加标题
<form id="form">
<table border=1px solid black>
<tr>
<td>#</td>
<td>Column-1</td>
<td>Column-2</td>
<td>Column-3</td>
<td>Column-4</td>
<td>Column-5</td>
<td>Column-6</td>
</tr>
<?php
$fp=fopen('sample.csv','r');
while(($data=fgetcsv($fp,1000,";"))!==FALSE){
$user=$DB->get_record('user',array('username'=>trim($data[0])));
echo '<tr>' .
'<td><input type="checkbox" name="username[]" value="' . $data[0] . '" checked="checked"/></td>' .
'<td>' . $data[0] . '</td><td>' . $user->firstname . '</td>' .
'<td>' . $user->lastname . '</td>' .
'<td>' . array_shift($dataClipNumber) . '</td>' .
'<td>' . $data[1] .'</td>' .
'<td>' . whatCourse(array_shift($dataClipCourse)). '</td>' .
'</tr>';
}
fclose($fp);
?>
</table>
<a href="javascript:;" onclick="document.getElementById('form').submit();">Save</a>
</form>
#
第1列
第2栏
第3栏
第4栏
第5栏
第6栏
编辑:您需要将
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
在“到html标题”部分中,修复页面上的特殊字符视图您可能还希望将其设置为在文件无法读取或文件为空时显示消息,以便在两个事件都为真时看起来不会只是不执行而已
<!-- set action to processor URL -->
<form action="process" method="post">
<table>
<caption>Table Caption</caption>
<thead>
<tr>
<th>Column 1</th>
<th>First Name</th>
<th>Last Name</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Course</th>
</tr>
</thead>
<tbody>
<?php $fp=fopen('sample.csv','r');
while(($data=fgetcsv($fp,1000,";"))!==FALSE){
$user=$DB->get_record('user',array('username'=>trim($data[0]))); ?>
<tr>
<td><?php echo $data[0]; ?></td>
<td><?php echo $user->firstname; ?></td>
<td><?php echo $user->lastname; ?></td>
<td><?php echo array_shift($dataClipNumber); ?></td>
<td><?php echo $data[1]; ?></td>
<td><?php echo whatCourse(array_shift($dataClipCourse)); ?>
</tr>
<?php }
fclose($fp);
?>
</tbody>
<tfoot>
<tr>
<th colspan="6">
<input type="submit" name="save" value="Save"/>
</th>
</tr>
</tfoot>
</table>
</form>
表格标题
第1栏
名字
姓
第4栏
第5栏
课程
如果文件无法读取或文件为空,您可能还希望将其设置为显示消息,以便在两个事件中的任何一个都为真时,该文件看起来都不会执行
<!-- set action to processor URL -->
<form action="process" method="post">
<table>
<caption>Table Caption</caption>
<thead>
<tr>
<th>Column 1</th>
<th>First Name</th>
<th>Last Name</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Course</th>
</tr>
</thead>
<tbody>
<?php $fp=fopen('sample.csv','r');
while(($data=fgetcsv($fp,1000,";"))!==FALSE){
$user=$DB->get_record('user',array('username'=>trim($data[0]))); ?>
<tr>
<td><?php echo $data[0]; ?></td>
<td><?php echo $user->firstname; ?></td>
<td><?php echo $user->lastname; ?></td>
<td><?php echo array_shift($dataClipNumber); ?></td>
<td><?php echo $data[1]; ?></td>
<td><?php echo whatCourse(array_shift($dataClipCourse)); ?>
</tr>
<?php }
fclose($fp);
?>
</tbody>
<tfoot>
<tr>
<th colspan="6">
<input type="submit" name="save" value="Save"/>
</th>
</tr>
</tfoot>
</table>
</form>
表格标题
第1栏
名字
姓
第4栏
第5栏
课程
谢谢您的帮助,但是复选框位于第一列的顶部,因此没有用户名看不见。如果我的解释模棱两可的话。用户名旁边的复选框。我试着给复选框一个自己的列,到目前为止仍然没有运气。没有看到按钮。你用过我更新的答案吗?您还可以分享您案例的屏幕截图吗?@user3178356查看我的更新答案。按钮不能丢失。怎么看不见?@user3178356查看我的更新答案。我已经将按钮移出了表格。没有更改,仍然是相同的视觉效果。感谢您的帮助,但是复选框保留在第一列的顶部,因此没有用户名不可见。如果我的解释模棱两可的话。用户名旁边的复选框。我试着给复选框一个自己的列,到目前为止仍然没有运气。没有看到按钮。你用过我更新的答案吗?您还可以分享您案例的屏幕截图吗?@user3178356查看我的更新答案。按钮不能丢失。怎么看不见?@user3178356查看我的更新答案。我已经将按钮移出了表格,没有任何变化,仍然是相同的视觉效果。