thanks for response.. but both answers are not clear to me.. and dond know how I change $i variable.
I used again my earlier code for my experiments and use some echo statements in inner while loop to check weather every my subjects come or not into my second while loop.. There I can see every subject relevant to categories has come into the while loop.. problem is when Im going to print those subjects in a two columns table using checkbox input tag... still its print a one subject row only...
This is that experimented code...
<?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) ) {
$category = $outRow['category_name'];
echo '<fieldset>';
echo '<legend><span>Category : <em style="color: red;">' . $category . '</em></span></legend>';
$innerQuery = "SELECT subject.subjects, subject.subject_id
FROM subject
INNER JOIN category_subject ON category_subject.subject_id= subject.subject_id
WHERE category_subject.category_id = {$outRow['category_id']}";
$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 $innerRow['subjects']; // here I can get all subject that relevant to one category
echo '<td width="50%"><input type="checkbox" name="subject[]" value="" /> ' . $innerRow['subjects'] . '</td>' . "\n";
$c++;
} // while..
// in case, to fill a last empty cell:
if ( ( $i % 2 ) != 0 ){
echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) );
}
echo "</tr></table>";
echo '</fieldset>';
}
?>
here I attached its output result... there u can see it only print 1 subject row under the categories. further If there is a one subject belong to one category it s not print any more in the table. see again attachment in 3rd category has a one subject but it doesn't print.