Please I need urgent help

with this code i have only fetched out the subjects and i need to fetch out value for the following too from the database…i have attached the template of what i want to achieve

  1. GRADE
  2. Contious Assessment:
  3. Exam Scores:
  4. Exam Scores
  5. Weighted Average:
  6. Last Term Cummulative:
  7. Cumulative (c+d)/2:
  8. Comment:
    but now i can only get the foreach work for subject alone…

$l=mysql_query(“SELECT * FROM result WHERE school_id=‘$id’ AND student_reg_id=‘$st’”) or die (mysql_error());

if (mysql_num_rows($l) > 0)
{
while ($row = mysql_fetch_array($l))
{//
$pwrlist[$row[‘ajax_result_id’]]=$row[‘subject’];
//$
}
$numpwr = count($pwrlist);
$thresh = 3;
$maxcols = 18;
$cols = min($maxcols, (ceil(count($pwrlist)/$thresh)));
$percol = ceil(count($pwrlist)/$cols);
$powerchk = ‘’;
$i = 0;
foreach ($pwrlist as $id => $pwr)
{
if (($i>0) && ($i%$percol == 0))
{
$powerchk .= “</td>
<td valign=‘top’>”;//echo “<br>”;
}

$powerchk .= " <table width=‘280px’ class=‘hovertable’>

<tr>
<td width=‘251px’ height=‘34’ align=‘left’ valign=‘middle’ bgcolor=‘#D6DFEB’><span class=‘style19’><font size=2px>$pwr</font></span></td>
<td width=‘19px’ align=‘left’ valign=‘middle’ bgcolor=‘#D6DFEB’><span class=‘style1’>GRADE:</span></td>
<td width=‘20px’ align=‘left’ valign=‘middle’ bgcolor=‘#FFFFFF’><span class=‘style13’>B3</span></td>
</tr>
<tr>
<td height=‘34’ colspan=‘3’ align=‘left’ valign=‘top’ bgcolor=‘#FFFFFF’><span class=‘style20’>» (a) Contious Assessment: 80

» (b) Exam Scores: 90

» (c) Weighted Average: 168

» (d) Last Term Cummulative: 78

» (e) Cumulative (c+d)/2: 123 </span></td>
</tr>
<tr>
<td height=‘20’ colspan=‘3’ align=‘left’ valign=‘top’ bgcolor=‘#FFFFFF’><span class=‘style17’>Comment: His is a responsible boy</span></td>
</tr>
</table><br>
";
$i++;
}

}

The table schemas would help.

That said, there are really two pieces to this. First creating the SQL to generate the data that you would like. Second, using PHP to parse the data and present it in the manor of your design. None of which can really be achieved without understanding tables your working with.

Since you’re querying the results table, I guess it contains the value you need as well. And since you’re doing a SELECT *, in the mysql result set returned by the query all the columns present in the table are at your disposition (including the column that contains the value you need).
So all you have to do is modify your code a bit and handle not only the subject column, but the other column(s) you need as well.
Starting with this loop:


while ($row = mysql_fetch_array($l)) {
  // add a line here for each column you need
  // you'll need to make a multi-dimensional array
  $pwrlist[$row['ajax_result_id']][B][COLOR="#FF0000"]['subject'][/COLOR][/B]=$row['subject'];
  [B][COLOR="#FF0000"]$pwrlist[$row['ajax_result_id']]['value']=$row['value'];[/COLOR][/B]
  ...
}

As you can see (marked in red) I transformed the $pwrlist array in a two dimensional array, so it can contain more column values for each row. And I added a line for the ‘value’ column (if it has another name in your database, modify accordingly).

Now you’ll have to modify the rest of your script to work with this 2-dimensional array and to display the extra information.