i am working on a college software and am stuck at a crucial point. i am running a query which will return studentid, names and rollno(s) and i need to display table columns with text boxes for assignment marks entry based on the teacher's input of number of assignments for a term. For instance, if user input is 3, i want to display 3 columns namely, Assignment 1, Assignment 2, Assignment 3 along with student name and rollno. the table rows will then have all students names with text boxes for entering marks for all three assignments. Also, i am displaying this table through ajax request which means php will have to create the output on the fly and display to user. I am assuming a nested loop will have to be used for this but am not sure how. Columns have to be created based on user input and rows should be based on mysql query result.
My code is:
$userinput = 3; // hypothetical
$q6 = mysql_query("select * from students");
while($row = mysql_fetch_array($q6)){
$data[] = $row;
}
echo "<table class='reglist' border='1' width='100%'>";
// start i loop
for($i=1;$i<=$userinput;$i++){
echo "<tr>
<th style='font-size:14px;'>S.No</th>
<th style='font-size:14px;'>Roll No</th>
<th style='font-size:14px;'>Name</th>
<th style='font-size:14px;width:50px;'>Assignment 1</th> // THESE COLUMNS SHUD BE BASED ON THE USER INPUT.
</tr>"; }
I am stuck here as to how to create table heads based on user input and then display rows according to the number of students returned by mysql.
Please help.