Possible Duplicate:
Inner while loop not working
这是一个来自我项目网页的代码抓取。 在这里我要显示用户选择的分类, 然后显示属于分类的主体。 在那里, 用户可能拥有超过一个分类, 并且我可以在第一个分类中打印所有这些类别, 环绕... 但问题是当 Im 试图打印主题时, 它只有一行。 每个分类中有更多的主题。 有人能告诉我发生了什么吗?
这是我的代码。 注意: 两个查询都正常工作。 我尝试了这些用户的 Mysql 客户程序 。
<?php
require_once ( ../../includes/config.inc.php );
require_once( MYSQL1 );
$outQuery = "SELECT institute_category.category_id, category_name
FROM institute_category
INNER JOIN category ON institute_category.category_id = category.category_id
WHERE institute_category.institute_id = $instituteId";
$outResult = mysqli_query( $dbc, $outQuery);
while ( $outRow = mysqli_fetch_array ( $outResult, MYSQLI_ASSOC) ) {
$categoryId = $outRow[ category_id ];
$category = $outRow[ category_name ];
echo <fieldset class="alt">
<legend><span>Category : <em style="color: red;"> . $category . </em></span></legend> ;
$innerQuery = "SELECT category_subject.category_id, category_subject.subject_id, subjects
FROM category_subject
INNER JOIN category ON category_subject.category_id = category.category_id
INNER JOIN subject ON category_subject.subject_id = subject.subject_id
WHERE category_subject.category_id = $categoryId";
$innerResult = mysqli_query( $dbc, $innerQuery);
$c = $i = 0;
echo <table class="form_table" ><tr> ;
while($innerRow = mysqli_fetch_array( $innerResult, MYSQLI_ASSOC )){
// if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row:
if( ($c % 2) == 0 && $c != 0){
echo "</tr><tr>";
}
echo <td width="50%"><input type="checkbox" name="subject[]" value=" . $innerRow[ category_id ] . ":" . $category . ":" . $innerRow[ subject_id ] . ":". $innerRow[ subjects ] . " /> . $innerRow[ subjects ] . </td> . "
";
$c++;
} // while..
// in case you need to fill a last empty cell:
if ( ( $i % 2 ) != 0 ){
// str_repeat() will be handy when you want more than 2 columns
echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) );
}
echo "</tr></table>";
}
echo </fieldset> ;
?>
这是我的HTML
good<fieldset class= alt >
<legend><span>Category : <em style= color: red; >grade 1 - 4</em></span></legend>
<table class= form_table ><tr>
<tr>
<td width= 50% ><input type= checkbox name= subject[] value= 2:grade 1 - 4:2:Art /> Art</td>
<td width= 50% ><input type= checkbox name= subject[] value= 2:grade 1 - 4:3:Art & Craft /> Art & Craft</td>
</tr>
<tr>
<td width= 50% ><input type= checkbox name= subject[] value= 2:grade 1 - 4:4:Bialogy /> Bialogy</td>
<td width= 50% ><input type= checkbox name= subject[] value= 2:grade 1 - 4:5:Buddhism /> Buddhism</td>
</tr>
</table>
<fieldset class= alt >
<legend><span>Category : <em style= color: red; >grade 5 (scholarship exam)</em></span></legend>
<table class= form_table ><tr>
<tr>
<td width= 50% ><input type= checkbox name= subject[] value= 3:grade 5 (scholarship exam):1:Agro & Food Technology /> Agro & Food Technology</td>
<td width= 50% ><input type= checkbox name= subject[] value= 3:grade 5 (scholarship exam):2:Art /> Art</td>
</tr>
<tr>
<td width= 50% ><input type= checkbox name= subject[] value= 3:grade 5 (scholarship exam):3:Art & Craft /> Art & Craft</td>
<td width= 50% ><input type= checkbox name= subject[] value= 3:grade 5 (scholarship exam):4:Bialogy /> Bialogy</td>
</tr>
</table>
<fieldset class= alt >
<legend><span>Category : <em style= color: red; >grade 6 - 10</em></span></legend>
<table class= form_table ><tr>
<tr>
<td width= 50% ><input type= checkbox name= subject[] value= 4:grade 6 - 10:2:Art /> Art</td>
<td width= 50% ><input type= checkbox name= subject[] value= 4:grade 6 - 10:3:Art & Craft /> Art & Craft</td>
</tr>
<tr>
<td width= 50% ><input type= checkbox name= subject[] value= 4:grade 6 - 10:4:Bialogy /> Bialogy</td>
<td width= 50% ><input type= checkbox name= subject[] value= 4:grade 6 - 10:5:Buddhism /> Buddhism</td>
</tr>
</table>
</fieldset>
如有任何意见,将不胜感激。
感谢您,感谢您