Hello friends,

I am displaying the comments suggested by 4 faculty members for each student. I want displaying three columns. Let me start with the second column first, which displays
the Faculty 1, faculty 2, faculty 3, faculty 4. The third row display respectively comments given by faculty. Ok. Now the first column should display 1,2,3,4...n.
Where n is the total no. of row in proposal table.

IN proposal table i have columns
-student_id
-first_name
-last_name

In grade table i have columns
-student_id
-faculty_id
-comments

For example if there are 3 rows in proposal table than output should be like

1 | faculty 1 | comments by faculty 1
| faculty 2 | comments by faculty 2
| faculty 3 | comments by faculty 3
| faculty 4 | comments by faculty 4
2 | faculty 1 | comments by faculty 1
| faculty 2 | comments by faculty 2
| faculty 3 | comments by faculty 3
| faculty 4 | comments by faculty 4
3 | faculty 1 | comments by faculty 1
| faculty 2 | comments by faculty 2
| faculty 3 | comments by faculty 3
| faculty 4 | comments by faculty 4

RIGHT NOW EVERYTHING IS SHOWING PROPERLY EXCEPT THE FIRST COLUMN. CAN YOU PLZ HELP ME OUT? I AM ATTACHING MY CODE

<h4><u>Comments</h3><br><br>
<?
$sql = "select * from proposal order by student_id";
$result = mysql_query($sql);
$num1=mysql_numrows($result);

while($rows=mysql_fetch_array($result))
{

?>
<table>
<tr>

<td>1</td>

<td><b><font size='2' face='Verdana'>Faculty 1</b></td>
<td><b></td>

<?

$s1="select comments from grade where student_id='".$rows['student_id']."' and faculty_id='20'";
$re = mysql_query($s1);
$num=mysql_numrows($re);
$i=0;
while ($i < $num) 
{
$comments=mysql_result($re,$i,"comments");

++$i;

}
if ($comments == '')
{
echo "<td >--</td>";
}
else
{
echo "<td ><font size='2' face='Verdana'>$comments</td>";
}?></tr>
<tr>
<td></td>
<td><b><font size='2' face='Verdana'>Faculty 2</td>
<td><b></td>
	
<?

$s1="select comments from grade where student_id='".$rows['student_id']."' and faculty_id='25'";
$re = mysql_query($s1);
$num=mysql_numrows($re);
$i=0;
while ($i < $num) 
{
$comments=mysql_result($re,$i,"comments");

++$i;

}
if ($comments == '')
{
echo "<td>--</td>";
}
else
{
echo "<td><font size='2' face='Verdana'>$comments</td>";
}?>
</tr><td></td>
<td><b><font size='2' face='Verdana'>Faculty 3</td>
<td><b></td>
<?

$s1="select comments from grade where student_id='".$rows['student_id']."' and faculty_id='22'";
$re = mysql_query($s1);
$num=mysql_numrows($re);
$i=0;
while ($i < $num) 
{
$comments=mysql_result($re,$i,"comments");

++$i;

}
if ($comments == '')
{
echo "<td >--</td>";
}
else
{
echo "<td ><font size='2' face='Verdana'>$comments</td>";
}
?></tr><td>4</td>
<td><b><font size='2' face='Verdana'>Faculty 4</td>
<td><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

<?

$s1="select comments from grade where student_id='".$rows['student_id']."' and faculty_id='1'";
$re = mysql_query($s1);
$num=mysql_numrows($re);
$i=0;
while ($i < $num) 
{
$comments=mysql_result($re,$i,"comments");

++$i;

}
if ($comments == '')
{
echo "<td>--</td>";
}
else
{
echo "<td><font size='2' face='Verdana'>$comments</td>";
}?>
</tr>

</table><?}?>

Each comment line should be in it's own <tr>. You now have all comments inside one <td>. That won't work. I'll see if I can post code later.

My guess is it should look something like this:

<h4>Comments</h4>
<table>
<?php
  $sql = "select * from proposal order by student_id";
  $result = mysql_query($sql);
    
  $faculties = array (20 => 'Faculty 1', 25 => 'Faculty 2', 22 => 'Faculty 3', 1 => 'Faculty 4');
  $number = 1;
    
  while ($rows = mysql_fetch_array($result))
  {
    foreach ($faculties as $id => $name)
    {
      echo "<tr><th>$number</th><th>$name</th><td>";
      $s1 = "select comments from grade where student_id='" . $rows['student_id'] . "' and faculty_id='$id'";
      $re = mysql_query($s1);
      while ($rw = mysql_fetch_array($re))
      {
        if (empty($rw['comments']))
        {
          echo "--";
        }
        else
        {
          echo $rw['comments'];
        }
        echo '<br/>';
      }
      echo '</td></tr>';
      mysql_free_result($re);
    }
    $number++;
  }
  mysql_free_result($result);
?>
</table>

Thanks a lot man....your code help me out.....

I have one more column named comments, which shows the no.of rows starting from 1.

For example, if table 1 has 4 entries than output of comments columns will be like

1
2
3
4

But i want to dispaly the odd number row of red color and even row has blue color....

I can paste the code if you want to make some changes in it.

Can you still help me out?

Thanks

Ok. I will paste the code in the new thread. But do reply in it. As i think you will be able to solve it.

Thanks

This article has been dead for over six months. Start a new discussion instead.