Jump to content

PHP using <table>

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
noprobz09

noprobz09

    Newbie

  • Members
  • Pip
  • 8 posts
I am a beginner in PHP, I am currently developing an Online Grading System.
I just to have ask any suggestions how to align the html table using PHP.

I have 2 records save in my TRAP table which are: chapter1 and chapter2...
this is my codes:
<table width="100">

<tbody>

<?php

 $trapTable=mysql_query("SELECT * FROM trap WHERE subCode='$code' AND instructor='$user'");

 while($trapResult=mysql_fetch_assoc($trapTable))

 {  ?>


<th>

 <?php

    //echo'<tr><th>';

    echo$trapResult['trapRecordName'];

    //echo'</th></tr>';

?>

</th>

<?php

    $recName=$trapResult['trapRecordName'];

    $gradeSql=mysql_query("SELECT *FROM gradebook WHERE recordName='$recName' AND instructor='$user' AND subCode='$code'");

    while($gradeResult=mysql_fetch_assoc($gradeSql))

     {

      echo'<tr>';

      echo'<td>';

      echo$gradeResult['studScore'];

      echo'</td>';

      echo'</tr>';

     }


 }

?>


</tbody>

</table>



In my codes above, It gives me a rigth output, but the problem is, all records are not align with the table, it goes like this:
------------------------------
chapter1
12
3
15
chapter2
49
28
5
--------------------------------
What I want is something like this:
===============================
Chapter1-----------chapter2
12--------------------49
3---------------------28
5---------------------15
===============================
in table format, Please give me some suggestions,...GOD BLESS!!!

#2
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Not very clean, but this should work. Untested.

<?php
	echo '<table width="100px" cellpadding="0" cellspacing="0" border="0">
			<tr valign="top">';
	$traptable = mysql_query("SELECT * FROM trap WHERE subCode='$code' AND instructor='$user'") or die(mysql_error());
	while($row = mysql_fetch_assoc($traptable))
	{
		echo '<td style="text-align:left;">
				<table cellpadding="0" cellspacing="0" border="0">
					<tr valign="top">
						<td align="center">
							' . $row['trapRecordName'] . '
						</td>
					</tr>';
					$gradetable = mysql_query("SELECT * FROM gradebook WHERE recordName='".$row['trapRecordName']."' AND instructor='$user' AND subCode='$code'") or die(mysql_error());
					while($row2 = mysql_fetch_assoc($gradetable))
					{
						echo '<tr valign="top">
								<td align="left">
									' . $row2['studScore'] . '
								</td>
							  </tr>';
					}
		echo '</table></td>';
	}
	echo '</tr>
	</table>';
?>

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#3
noprobz09

noprobz09

    Newbie

  • Members
  • Pip
  • 8 posts
thanks for your brilliant ideas...