Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:16:17+00:00 2026-06-17T04:16:17+00:00

I am going to create a HTML form dynamically with php. Using that form

  • 0

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.

// 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'];

        $subjects = array();

        $subjects[] = $row['sn'];

        echo '<div>';

        //Detect change in category
        if($catID != $categoryId) 
        {
            echo "<h3>Category 01: <span>{$category}</span><span></span></h3>";
            echo "<div class='container'>";

            echo '<table>'; 

            $j = 0;

            foreach ( $subjects AS $sub ) {
                if($j%2 == 0 && $j == 0)
                {
                    echo '<tr>';
                    echo '<td width="50%"><input type="checkbox" value="1" name="subjects[]">'.$sub.'</td>';
                }
                else if($j%2 == 0)
                {
                    echo '</tr><tr>';
                    echo '<td width="50%"><input type="checkbox" value="1" name="subjects[]">'.$sub.'</td>';
                }
                echo '<td width="50%"><input type="checkbox" value="1" name="subjects[]">'.$sub.'</td>';
                $j++;
            }
            echo '</tr>'; 
            echo '</table>';    
            echo "</div> <!-- End .container DIV -->\n";            
        }
        $catID = $categoryId;       
        echo '</div>';
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:16:18+00:00Added an answer on June 17, 2026 at 4:16 am

    You will have to have 2 loops for that as below.

    foreach/for loop to create the categories
    {
     foreach/for another loop inside above loop to create levels
     here you can have a table with two columns`<td>`
    
      Apply below logic to create a row with two columns`<td>`
      //$i is the counter, when you loop through once you increase the $i by one.
      if($i%2 == 0)
      //add new `<tr>`. If it's $i != 0 close the <tr> before opening one.
    }
    

    If you have any issues let me know.

    Let’s assume is as below. Create the arrays as below from SQL

        levels_array[1][] = "pre school" //cat 1 levels
        levels_array[1][] = "pre school 1" //cat 1 levels 
        levels_array[1][] = "pre school 2"  //cat 1 levels
        levels_array[2][] = "school 2"  //cat 2 levels
        levels_array[2][] = "school 2"  //cat 2 levels
        levels_array[3][] = "college" //cat 3 levels
    
        cat_array[1] = "catgeory 1" 
        cat_array[2] = "catgeory 2" 
        cat_array[3] = "catgeory 3" 
    
    
    for($i = 1; < count($cat_array); $i++)
    {
    
    foreach(levels_array[$i] as $item)
    {
    //create the table with the above mentioned logic
    }
    
    }
    

    According to the updated question

    echo '<table>'; $j = 0;
    foreach ( $subjects AS $sub ) {
    if($j%2 == 0 && $j == 0)
    {
      echo '<tr>';
      echo '<td>'.$sub.'</td>';
    }
    else if($j%2 == 0)
     {
      echo '</tr><tr>';
      echo '<td>'.$sub.'</td>';
     }
    echo '<td>'.$sub.'</td>';
    $j++;
    
    }
    echo '</tr>'; 
    echo '</table>';  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three simple html or php file that I'm going to create. What
Using mysql_query results to create an html form like below with auto incremented prefixed
Each user can dynamically create a table from a form. I am trying to
I have two combo boxes in an html form that are going to be
i'm using powerplot to create a dynamic graph in iphone. while going through http://www.field-theory.org/articles/powerplot/example.html
I am going to create a script that sends out an email. I am
I am going to create a typical business application that will be used by
I can create database manually by going to cpanel. But I'd like to create
I am building an multiple file upload form that user can use to upload
So I have an HTML form where a user can upload an image. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.