0

我正在获取每条记录的单个 tsid 的值,但是数组中未返回选中的单选按钮值,我只得到 0?任何帮助表示赞赏。

PHP:

// Set the timesheets to set status approved/rejected
// find out how many records there are to update
$size = count($_POST['tsid']);

// start a loop in order to update each record
$i = 0;
while ($i < $size) {
// define each variable
$tsid = intval($_POST['tsid'][$i]);
$personnelid = intval($_POST['personnel'][$i]);
print "TSID: " . $tsid . "<br>";
print "TSuser: " . $personnelid . "<br>";
if ($tsid > 0 && $personnelid > 0) {
// do the update and print out some info just to provide some visual feedback
$query = "Update timesheets set status='1' where id= '$tsid' LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
}
++$i;
}
mysql_close();

HTML:

<input type="hidden" name="tsid[]" value="<?PHP echo $row['id']; ?>">
<li data-role="fieldcontain">
    <a href="tsapprove.php?id=<?PHP echo $row['id']; ?>"><p><?PHP echo $row['personnel']; ?></p>
    <p><?PHP echo $row['name']; ?></p>
    <p class="ui-li-aside"><strong><?PHP echo $row['totalhrs']; ?> H</strong></p>
<fieldset data-role="controlgroup" data-type="horizontal">
    <input type="radio" name="personnel[]" id="1" value="<?PHP echo $row['personnel']; ?>"  />
      <label for="1">Approve</label>
      <input type="radio" name="personnel[]" id="2" value="<?PHP echo $row['personnel']; ?>"  />
      <label for="2">Reject</label>
    </fieldset>
</a>
<a href="tsapprove.php?id=<?PHP echo $row['id']; ?>">View Details</a>
</li>
4

1 回答 1

0

希望你能把它拼凑起来:

<?

$size = count($_POST['tsid']);

echo "<pre>";print_r($_POST);echo "</pre>";

$i = 0;
while ($i < $size) {
  $tsid = $_POST['tsid'][$i];
  $pid = $_POST['personnel_'.$i];


  print "TSID: " . $tsid . "<br />";
  print "TSuser: " . $pid . "<br />";

  $i++;
}

?>
<form method="post">
<!--tsid[0] - $i = 0-->
<input type="hidden" name="tsid[]" value="1" />
<input type="radio" name="personnel_0" value="111" />
<input type="radio" name="personnel_0" value="222" />

<!--tsid[1] - $i = 1-->
<input type="hidden" name="tsid[]" value="2" />
<input type="radio" name="personnel_1" value="333" />
<input type="radio" name="personnel_1" value="444" />
<input type="submit" />
</form>

基本上,您返回人员的方式并没有真正起作用。所以我稍微简化了一点,基本上为人员设置了不同的收音机。它使用 TSID 值设置实际名称,而不是数组。

我对 1 和 2 进行了硬编码,但您可以用 $row['id'] 替换,“personnel_”之后的数字也会是 0..1..2 等

希望这会有所帮助

编辑:代码的一些问题

于 2012-04-09T22:35:38.450 回答