使用单选按钮检查更新多行

时间:2012-04-09 22:04:03

标签: php jquery-mobile

我为每条记录获取单个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>

1 个答案:

答案 0 :(得分: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等

希望这会有所帮助

编辑:代码

的问题很少