dongmibeng5885 2016-01-12 19:26
浏览 53

如何在html中使用数据库表的列的复选框?

Pretty much title. I'm new to html and just wanted to know how I'd be able to filter out columns on a database table. Here's what I got:

<?php
$link=@mysql_connect('localhost','root','');
mysql_select_db("home_work");
$sql="SELECT * FROM employee ";
$aResult=mysql_query($sql);

?>
<html>
<body bgcolor="Orange">
<H1>
<center>
<?php
echo '<p>Testing SQL table</p>' ; 
?></p>
</center>
</H1>



<form action="columnChecks.php">
  <input type="checkbox" name="columna" value="a1"> Column 1<br>
  <input type="checkbox" name="columna" value="a2" > Column 2<br>
  <input type="submit" value="Submit">
</form>



<form name="frmForm" id="frmForm" >
<table border="1" width="30%" height="30%"> 
<tr>
<th><font color='Purple'>ID</font></th>
<th><font color='Purple'>NAME</font></th>
<th><font color='Purple'>ADDRESS</font></th>
<th><font color='Purple'>DESIGNATION</font></th>
<th><font color='Purple'>SALARY</font></th>
</tr> 

<?php

while($rows = mysql_fetch_array($aResult,MYSQL_ASSOC))
{ 
$id           = $rows['id'];
$empid        = $rows['empid'];
$empname      = $rows['empname'];
$empaddress   = $rows['empaddress'];
$designation  = $rows['designation'];
$salary       = $rows['salary']; 
?>
<tr>

<td><b><font color='#663300'><?php echo $empid;?></font></b></td>
<td><b><font color='#663300'><?php echo $empname;?></font></b></td>
<td><b><font color='#663300'><?php echo $empaddress;?></font></b></td>
<td><b><font color='#663300'><?php echo $designation;?></font></b></td>
<td><b><font color='#663300'><?php echo $salary;?></font></b></td>

</td>
</tr>

<?php } ?>
</table>
</form>
</body>
</html>

So I'm trying to make it so that the user will check whatever columns he/she wants displayed, and then a table will be made with only those columns.

First question: instead of using "Column 1" and "Column 2", is there a way I can pull out the name of the column itself and then insert the respective column's names in the place of "Column 1" and "Column 2"?

Whenever I just click on any of the buttons, it gives me a blank page (probably because I have nothing on the columnChecks.php document. How exactly do I handle the output from the submit form? I know the action attribute is columnChecks.php and that is where stuff goes down, the thing is I just don't know where to start that..

  • 写回答

1条回答 默认 最新

  • doutan8601 2016-01-12 20:39
    关注

    That will help you: https://www.datatables.net/

    That's the moment when HTML+PHP is not enough to achieve your goal (at least not easy way) and you need to get some help from JavaScript.

    Good luck and have fun!

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?