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 6652783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:11:02+00:00 2026-05-26T01:11:02+00:00

I have this code that fetches data from mySQL and outputs it as an

  • 0

I have this code that fetches data from mySQL and outputs it as an array(multidimensional) like so:

$res = @mysqli_query($dbc, "SELECT id, subject, exam, marks, remarks  FROM log WHERE student = '2222' AND term = 'Term2'");
$studentMarks = array();

while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC))
{
    $studentMarks[$row['subject']][$row['exam']] = $row['marks'];
}



//So far the code displays $studentMarks like this:
//$studentMarks = array(
//    Maths => array('CAT1' => 50, 'CAT2' => 35)
//  , English => array('CAT1' => 20, 'MIDTERM' => 40)
//);

//I wish it to add remarks thus displaying $studentMarks like:(Not sure whether I am right)
//$studentMarks = array(
//    Maths => array('CAT1' => array(50,
//          "Good"
//          ), 
//      array('CAT2' => array(35,
//          "Can do better"
//          )
//)
//  , English => array('CAT1' => array(20,
//          "Good"
//          ), 
//      array('MIDTERM' => array(40,
//          "Much better"
//          )
//);

echo '<table><thead><tr>';
echo '<td>Student</td><td>CAT1</td><td>CAT2</td><td>MIDTERM</td>';
echo '</tr></thead><tbody>';



foreach($studentMarks as $studentSub => $marks)
{
  echo '<tr>';
  echo '<td>', $studentSub, '</td>';
  echo '<td>', (isset($marks['CAT1']) ? $marks['CAT1'] : '&nbsp;'), '</td>';
  echo '<td>', (isset($marks['CAT2']) ? $marks['CAT2'] : '&nbsp;'), '</td>';
  echo '<td>', (isset($marks['MIDTERM']) ? $marks['MIDTERM'] : '&nbsp;'), '</td>';
  echo '</tr>';
}

echo '</tbody></table>';

//END CODE

I am trying to achieve this:

SUBJECT CAT 1 | CAT 2 | MIDTERM | ENDTERM

MATH        50        35
                 Good    Can do better
ENGLISH  20                      40
                 Can do better    Do better

QUESTION:

How can I display remarks under/against each marks displayed?

Your Help is Much Appreciated…

  • 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-05-26T01:11:03+00:00Added an answer on May 26, 2026 at 1:11 am
    $res = @mysqli_query($dbc, "SELECT id, subject, exam, marks, remarks  FROM log WHERE student = '2222' AND term = 'Term2'");
    $studentMarks = array();
    
    while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC))
    {
        $studentMarks[$row['subject']][$row['exam']]['mark'] = $row['marks'];
    
        //This will get the remarks from the database
        $studentMarks[$row['subject']][$row['exam']]['remark'] = $row['remarks'];
    
        //This should be used when you chose to compare marks and display appropriate remarks
        //$studentMarks[$row['subject']][$row['exam']]['remark'] = ( $row['marks'] < 40)?'can do better':( $row['marks'] < 50)?'do better':'good';
    }
    
    
        echo '<table><thead><tr>';
        echo '<td>Student</td><td>CAT1</td><td>CAT2</td><td>MIDTERM</td>';
        echo '</tr></thead><tbody>';
    
    
    
        foreach($studentMarks as $studentSub => $marks)
        {
          echo '<tr>';
          echo '<td>', $studentSub, '</td>';
          echo '<td>', (isset($marks['CAT1']) ? $marks['CAT1']['mark'] : '&nbsp;'), '</td>';
          echo '<td>', (isset($marks['CAT2']) ? $marks['CAT2']['mark'] : '&nbsp;'), '</td>';
          echo '<td>', (isset($marks['MIDTERM']) ? $marks['MIDTERM']['mark'] : '&nbsp;'), '</td>';
          echo '</tr>';
    
          echo '<tr>';
          echo '<td> </td>';
          echo '<td>', (isset($marks['CAT1']) ? $marks['CAT1']['remark'] : '&nbsp;'), '</td>';
          echo '<td>', (isset($marks['CAT2']) ? $marks['CAT2']['remark'] : '&nbsp;'), '</td>';
          echo '<td>', (isset($marks['MIDTERM']) ? $marks['MIDTERM']['remark'] : '&nbsp;'), '</td>';
          echo '</tr>';
        }
    
        echo '</tbody></table>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that fetches some text from a page using BeautifulSoup soup=
So I have this code that takes care of command acknowledgment from remote computers,
I have a silverlight 3 application, that fetches some simple data from a ms-sql-server
I have a php script that fetches data from a DB, the result set
I have a PHP script (fetchData.php) that fetches some data and outputs it to
I have an app that fetches data (a list of countries) from an sqlite
I have a rake task that fetches JSON data from an API, parses it,
I have this code that performs an ajax call and loads the results into
I have this code that works in a unit test but doesn't work when
I have this code that I want to make point-free; (\k t -> chr

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.