我每页有四行。直接解析的四行形成mysql表。每行都有一个复选框。我想知道选中了哪个复选框。在下面显示的代码中,它仅保存页面的第一行。因此,如果我选择第三行,它将显示为选择的第一行。我正在使用 onchange 方法来知道选择了某些东西,但我还不知道如何获得它。
有人可以帮忙吗?
<?php
//limit for number of categories displayed per page
$limit = 4;
$categoriesNum= mysql_query("SELECT COUNT('categoryTopic') FROM categories");
//number of current page
$page =(isset($_GET['page']))? (int) $_GET['page'] :1;
//calculate the current page number
$begin =($page - 1)* $limit;
//number of pages needed.
$pagesCount =ceil(mysql_result ($categoriesNum,0)/$limit);
//Query up all the Categories with setting the Limit
$CategoryQuery = mysql_query ("SELECT categoryTopic From categories ORDER BY categoryTopic LIMIT $begin, $limit");
//Place all categories in an array then loop through it displaying them one by one
while ($query_rows = mysql_fetch_assoc($CategoryQuery))
{
$category =$query_rows['categoryTopic'];
//echo $category;
//query all the subcategories that the current category has
$Sub = mysql_query ("SELECT categoryTopic FROM subcategories WHERE categoryTopic='$category'");
$Count = mysql_num_rows ($Sub);
echo '<table width="85%" border="1" cellpadding="0"; cellspacing="0" align="center">
<tr>
<th width="23%" height="44" scope="col" align="left"> '.$query_rows['categoryTopic'].' <br><br><br></th>
<th width="24%" scope="col">'.$Count.'</th>
<th width="25%" scope="col"> 0 </th>
<th width="28%" scope="col"> <form name = "choose">
<label><input type="checkbox" id ="check" value= '.$category.' onchange="handleChange(this);"></label>
</tr>
</table>';
}
?>
<script type="text/jscript">
//this function will be called when user checks a check box.
function handleChange(cb) {
//get the selected category
var category = document.getElementById('check').value;
document.write(category);