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

  • SEARCH
  • Home
  • 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 8280233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:35:58+00:00 2026-06-08T09:35:58+00:00

I am creating a school type CMS system in php to get more experience.

  • 0

I am creating a school type CMS system in php to get more experience.
I created a schedule.php page where it lists the school categories, for example:

Accounting
Biology
Math
Computer Science

I want to add put a number next to the category Accounting(2) coming from the database because there is 2 accounting classes. for example Computer Science has 10 classes taught so it should be Computer Science(10)

My code only dispalys the name of the subject not the number of classes taught.

here is my code:

<?php


include('connect.php');

if(!isset($_GET['id']))
{
    ?>
    <table border="1" width="15%" height="137">
<tr>
    <td><?php

    //$query1 = mysql_query("SELECT * FROM categories ORDER BY category_name") or die(mysql_error());


    $query1 = mysql_query("SELECT CONCAT(a.category_name, ' (', COUNT(b.category_id), ')') AS category

FROM categories a
LEFT JOIN classes b ON a.id = b.category_id
GROUP BY a.id, a.category_name”) or die(mysql_error());

    while($row = mysql_fetch_object($query1))
    {
        print "<a href='schedule.php?id=" . $row->id .  "'>" . $row->category . "</a><br/>";
    } ?></td>
</tr>

    <?php


}
//if you click on the subject
else if(isset($_GET['id']))
{
    $category = $_GET['id'];
    $sql = "SELECT * FROM classes WHERE category_id = " . $category;
    $query2 = mysql_query($sql) or die(mysql_error());


    while($row = mysql_fetch_object($query2))
    {
    ?>

    <center><h3><?php echo $row->class_name . '-' . $row->units; ?>  </h3></center>
    <table border ="0" wdith="100%">
    <tr>
    <td>
    <strong>Description: </strong>
    <?php echo $row->class_description; ?>
    </tr>
    </td>
    </table>
    <br/>
    <table border="1" width="44%">
<tr>
    <td width="60"><b>Ticket</b> </td>
    <td width="123"><b>Days</b></td>
    <td width="120"><b>Hours</b></td>
    <td width="64"><b>Room</b></td>
    <td><b>Instructor</b></td>
</tr>


    <tr>
    <td width="60"> <?php echo $row->ticket; ?> </td>
    <td width="123"><?php echo $row->days; ?></td>
    <td width="120"><?php echo $row->start_hours . $row->time_format . '-' . $row->end_hours . $row->time_format2 ;  ?> </td>
    <td width="64"> <?php echo $row->room_number; ?></td>
    <td><?php echo $row->instructor_name;  ?></td>
</tr>

    }//end while

}//end else if

?>

Thanks

  • 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-08T09:36:00+00:00Added an answer on June 8, 2026 at 9:36 am

    Assuming your schema is along the lines of:

    +---------------+     +--------------------+
    | categories    |     | classes            |
    +---------------+     +--------------------+
    | ID            |     | id                 |
    | category_name |     | category_id        |
    | etc..         |     | etc...             |
    +---------------+     +--------------------+
    

    Where classes.category_id is a foreign key referencing categories.id, there is quite a simple solution:

    SELECT a.ID, CONCAT(a.category_name, ' (', COUNT(b.category_id), ')') AS category
    FROM categories a
    LEFT JOIN classes b ON a.ID = b.category_id
    GROUP BY a.ID, a.category_name
    

    This will concatenate the count of classes to each category. Ex.

    Biology (4)
    Computer Science (10)
    etc...
    

    And you can simply reference the category column of the query in your PHP.

    while($row = mysql_fetch_object($query1))
    {
        print "<a href='schedule.php?id=" . $row->ID .  "'>" . $row->category . "</a><br/>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a system for my dissertation for a school to use. There's
I'm creating a contest sign-up page for our annual math competition at my school.
I'm working on a school project creating a CMS for my portfolio site. I
I'm creating an equipment reservation (PHP/MySQL) for my school. My database looks like this:
I'm creating web application for my friend, a tutor school system. Now, I'm having
I have an interest in creating a NoSQL database system for a school project
I am creating a school project of music player and already created the GUI.
I am creating a school management system that handles file uploads and downloads from
I'm creating a old school music emulator for the old GWBasic PLAY command. To
I'm creating an iOS project for school and it works with chemical reactions. The

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.