当前位置:编程学习 > php >>

php 编程 文本框数值传递问题

如图,两排文本输入框上下对应的输入框的名字是一样的,问怎样取得他们的值并插入数据库?最后50分了,求正解啊!
答案:这50分应该我拿了..嘿嘿...
方式:通过传递数组给php页面.
举例:

<form action='sub.php' method='method' name='form_1'>
<div><input type="text" name="realname[]" ></div>
<div><input type="text" name="realname[]" ></div>
<div><input type="text" name="realname[]" ></div>
<div><input type="text" name="realname[]" ></div>
<div><input type="text" name="realname[]" ></div>
</form>

====sub.php===================================================

<?

print_R( $realname );

?>

例子看明白了吗?其实很简单 ,表单中name对应php的一个变量,如果name等于"realname[]",对应的是php的一个数组..甚至可以是三维 ..四维...这个以后慢慢体会吧..用数组传递非常方便.
比如:会员注册,你可以这么传递

<div><input type="text" name="reg[realname]" ></div>
<div><input type="text" name="reg[sex]" ></div>
<div><input type="text" name="reg[pwd]" ></div>
<div><input type="text" name="reg[email]" ></div>
.
.
.

不管有更多的。都可以只通过一个reg数组传递.

你的例子,我觉得可以这么写
方法一: 非常直接滴

while($row=mysql_fetch_array($result))
{?>
<tr align='center' bgcolor='#FAFAF1'>
<td height='24'><input class='np' type='checkbox' name='del[]' value="<?php echo $row['job_number'];?>"</td>
<td height='24'><input type="text" name="job_number[]" value="<?php echo $row['job_number']; ?>" readonly="readonly" style="width:50px"></td>
<td height='24'><input type="text" name="name[]" value="<?php echo $row['name']; ?>" readonly="readonly" style="width:50px"></td>
<td height='24'><input type="text" name="level[]" ></td>
<td height='24'><input type="text" name="targer[]" ></td>
<td height='24'><input type="text" name="achieve[]" ></td>
<td height='24'><input type="text" name="y_points[]" ></td>
<td height='24'><input type="text" name="q_points[]" ></td>
<td height='24'><input type="text" name="s_points[]" ></td>
</tr><?php }?><tr>

在php中就可以接受到 $del $job_number $name $level $targer $achieve $y_points $q_points $s_points等这些数组.

如果我碰到这样的问题,我用下面的方法,高效 ,简洁
方法二:
假设$row数组中有主键,且名称为id.

while($row=mysql_fetch_array($result))
{?>
<tr align='center' bgcolor='#FAFAF1'>
<td height='24'>
<input class='np' type='checkbox' name='data[$row[id]][del]' value="<?php echo $row['job_number'];?>"</td>
<td height='24'><input type="text" name="data[$row[id]][job_number]" value="<?php echo $row['job_number']; ?>" readonly="readonly" style="width:50px"></td>
<td height='24'><input type="text" name="data[$row[id]][name]" value="<?php echo $row['name']; ?>" readonly="readonly" style="width:50px"></td>
<td height='24'><input type="text" name="data[$row[id]][level]" ></td>
<td height='24'><input type="text" name="data[$row[id]][targer]" ></td>
<td height='24'><input type="text" name="data[$row[id]]achieve" ></td>
<td height='24'><input type="text" name="data[$row[id]][y_points]" ></td>
<td height='24'><input type="text" name="data[$row[id]][q_points]" ></td>
<td height='24'><input type="text" name="data[$row[id]][s_points]" ></td>
</tr><?php }?><tr>

这些接受的好处.1.只需要传递$data. 2.保持数据一致性.
手打字软了.
给你一个学习的地址吧.有事可以留言

http://hi.zhaoxi.net/iostream210

上一个:学php必须先学c语言么
下一个:mysql数据库问题(php)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,