thara Posted January 11, 2013 Share Posted January 11, 2013 (edited) Its difficulty to explain my problem with my English knowledge. But I will try my best. I am going to create a HTML form dynamically with php. Using that form users can select subjects under different category. A category and Its subjects have broken to one logical section and have applied jquery accordion. In my form I need to create more logical section like that. this is my HTML <form action="" method="post"> <div id="accordion"> <!-- logical section 1 --> <div> <h3>Category 01: <span>category name</span><span></span></h3> <div class="container"> <table> <tr> <td width="50%"> <input type="checkbox" value="1" name="subject[]">subject1 </td> <td width="50%"> <input type="checkbox" value="2" name="subject[]">subject2 </td> </tr> </table> </div> </div> <!-- logical section 2 --> <div> <h3>Category 02: <span>category name</span><span></span></h3> <div class="container"> <table> <tr> <td width="50%"> <input type="checkbox" value="1" name="subject[]">subject1 </td> <td width="50%"> <input type="checkbox" value="2" name="subject[]">subject2 </td> </tr> </table> </div> </div> </div> </form> Now I am trying to generate above form dynamically using category values which come from sessions. This is the PHP code I have tried so far.. <form action="" method="post"><br /> <div id="accordion"> <?php // Check SESSION fromm category page if ( isset ( $_SESSION['category']) && is_array( $_SESSION['category'])) { $categoryIds = implode(',', $_SESSION['category']); $q = "SELECT c. category_id AS ci, c.category_name AS cn, s.subject_name AS sn, s.subject_id AS si FROM category AS c INNER JOIN category_subjects AS cs ON cs.category_id = c.category_id INNER JOIN subjects AS s ON s.subject_id = cs.subject_id WHERE c.category_id IN ($categoryIds)"; $r = mysqli_query( $dbc, $q) ; $catID = false; $max_columns = 2; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $categoryId = $row['ci']; $category = $row['cn']; //Detect change in category if($catID != $row['ci']) { if($catID!=false) { if($recCount % $max_columns != 0) { //Close previous row echo "</tr>\n"; } //Close previous table echo "</table>\n"; } $catID = $row['ci']; echo "<div>\n"; echo "<h3>Category 01: <span>{$category}</span><span></span></h3>\n"; echo "<div class='container'>\n"; echo "<table><tr>\n"; $recCount = 0; } $recCount++; if($recCount % $max_columns == 1) { echo "<tr>\n"; } $value = "{$row['ci']}:{$category}:{$row['si']}:{$row['sn']}"; echo "<td width='50%'>"; echo "<input type='checkbox' name='subject[]' value='{$value}' />{$row['sn']}"; echo "</td>\n"; if($recCount % $max_columns == 0) { echo "</tr>\n"; } if($recCount % $max_columns != 0) { //Close last row echo "</tr>\n"; } //Close last table echo "</table>\n"; echo "</div></div>"; } } ?> </div> <!-- end #accordion div --> </form> Can anybody tell my where I am going wrong? I troubled how to create inner table with 2coloms..... Thank you.. Edited January 11, 2013 by thara Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.