将主复选框和子复选框插入表中

时间:2014-03-14 09:13:25

标签: php html sql

我的代码问题尤其是关于复选框的问题。好的,这是我的代码:

$sql = "SELECT * FROM logistic_manager ORDER BY id_lm";
$main = mysql_query($sql);

while($r = mysql_fetch_array($main)) {
  echo " + <input type='checkbox' name='cx[]' value='$r[id_lm]' /><b>$r[logistic_manager]</b><br>";
  $sql2 = "SELECT * FROM area, logistic_manager WHERE area.id_lm = logistic_manager.id_lm AND area.id_lm = $r[id_lm]";       
  $sub = mysql_query($sql2);
  $jml = mysql_num_rows($sub);
  if($jml > 0) {
    while($w=mysql_fetch_array($sub)){
      echo "&nbsp &nbsp &nbsp - <input type='checkbox' name='cxsub[]' value='$w[id_area]' />$w[area] - $w[id_area]<br>";
    }
  } else { print "<br> &nbsp &nbsp &nbsp - Subuser undefined<br>";}
  print "<br>";
}

输出html:

+ Logistic Manager id-> 1 (selected)
      - A ->id: 5 (selected)
      - B ->id: 9
      - C ->id: 10 (selected)

+ Logistic Manager id-> 2 (selected)
      - D ->id: 6 (selected)

+ Logistic Manager id-> 3 
      - E ->id: 7

+ Logistic Manager id-> 4
      - F ->id: 8
抱歉,复选框不应该列出..

问题是如何将选中的复选框插入表格? 如果有人可以帮助我,我很高兴...在此之前感谢:)

1 个答案:

答案 0 :(得分:0)

复选框不显示...

未经测试的代码:

我们想要的输出行,名称和值由“marks:

包围
+ <input type="checkbox" name="cx[]" value="$r[id_lm]" /><b>$r[logistic_manager]</b><br>

获得它的一种方法......

echo ' + <input type="checkbox" name="cx[]" value="'. $r[id_lm] .'" /><b>'. $r[logistic_manager] .'</b><br>';