我想要完成的是
我已经使每个输入/值都有自己的名称/ id,例如。 (name0,name1,name2)
我只是不太确定如何从表中获取所有数据到MySQL数据库
继承我目前的代码:
$query = "SELECT ID, name, date, start, end, location, leavetype, comments FROM test WHERE `start`='' AND `date`<>'$today_date' OR `end`='' AND `date`<>'$today_date'";
$result=mysql_query($query);
$num=mysql_numrows($result);
?>
<section>
<form>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th hidden>
<font face="Arial, Helvetica, sans-serif">Datename</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">ID</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">Name</font>
</th>
<th width="80px">
<font face="Arial, Helvetica, sans-serif">Date</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">Start</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">End</font>
</th>
<th style="width:120px;">
<font face="Arial, Helvetica, sans-serif">Location</font>
</th>
<th style="width:80px;">
<font face="Arial, Helvetica, sans-serif">Leave-Type</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">Comments</font>
</th>
</tr>
<?php
$i=0;while ($i < $num) {$f1=mysql_result($result,$i,"ID");
$f2=mysql_result($result,$i,"name");
$f3=mysql_result($result,$i,"date");
$f4=mysql_result($result,$i,"start");
$f5=mysql_result($result,$i,"end");
$f6=mysql_result($result,$i,"location");
$f7=mysql_result($result,$i,"leavetype");
$f8=mysql_result($result,$i,"comments");
echo '
<tr>
<td hidden>
<font face="Arial, Helvetica, sans-serif">';echo "$f3$f2";echo '</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="ID'; echo $i; echo '" style="width:35px;" Value="'; echo $f1;echo '" style="width:80px" disabled></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="name'; echo $i; echo '" style="width:120px;" Value="'; echo $f2;echo '" style="width:80px" disabled></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="date'; echo $i; echo '" pattern="[0-9]{2}/[0-9]{2}/[0-9]{4}$" style="width:65px;" Value="'; echo $f3;echo '" style="width:70px" disabled> </font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="start-time'; echo $i; echo '" pattern="[0-9]{2}:[00,15,30,45]{2}$" style="width:35px;" Value="'; echo $f4;echo '" style="width:35px"></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="end-time'; echo $i; echo '" pattern="[0-9]{2}:[00,15,30,45]{2}$" style="width:35px;" Value="'; echo $f5;echo '" style="width:35px"></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <select name="location'; echo $i; echo '"><option value="'; echo $f6;echo '">'; echo $f6;echo '</option></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <select name="leavetype'; echo $i; echo '"><option value="'; echo $f7;echo '">'; echo $f7;echo '</option></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="rcomment'; echo $i; echo '" style="width:120px;" Value="'; echo $f8;echo '" style="width:70px"></font>
</td>
</tr> ';
++$i;}
if ($i=="0"){echo '<tr><td colspan="9"><p style="color: Green; font-size: 35px; font-weight:bold; text-align: center">All signed in-out correctly!</p></td></tr>';}
else if ($i > "0"){ echo '<tr><td colspan="9"><input name="Submit" type="Submit" Value="Update">';}
?>
如何设置第二行和后续行值
$ users_name = $ _POST ['name']; //员工姓名
$ users_leavetype = $ _POST ['leavetype']; //如果有的话留下类型(例如:年假)
$ users_date = date('d / m / Y',strtotime($ _ POST ['rdate'])); //日期
$ users_start = $ _POST ['start-time']; //开始时间
$ users_finish = $ _POST ['end-time']; //完成时间
$ users_location = $ _POST ['location']; //他们原来的位置
$ users_comment = $ _POST ['rcomment']; //管理员评论
我必须添加每个变量吗?还是有更简单的方法
注意:第二批代码来自另一个表单,因此不会更改此表单,只显示我正在使用的格式,并且不确定如何编辑我需要的内容
所有帮助赞赏
答案 0 :(得分:0)
你在mysql_num_row()
中犯了错误;其
$num=mysql_num_rows($result);
不
$num=mysql_numrows($result);
阅读手册mysql_num_row()
答案 1 :(得分:0)
成功,
我自己想通了[= 我不得不在表的末尾添加一行,结尾值为$ i
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
然后这是我的
<tr hidden>
<td hidden>
<input type="text" name="ivalue" style="width:120px;" Value="'; echo $i;echo '" style="width:70px" hidden></font>
</td>
</tr>
由于某些原因我不得不确定++ $ max,也许如果我将其设置为“while($ i&lt;&gt; $ max)它可能没有它,但无论如何这里是我做的
<form action="senddata.php" file>
注意:datename是我的唯一专栏,所以有人在一天内无法登录/退出