Hello,
I'm pulling classes from a database and displaying them in dropdown boxes for the users to choose from. I need to be able to take the courseIDs(in my database) from the courses they pick and store them into a table called account_courses. I also wanted the drop-down boxes to start out blank so if they didn't want to add a class in that box they didn't have to. I'm not sure how to implement the variables so I can take in the courseID with accountID. Here is my code:
<?php
/**
*/
class addCoursePage extends webPage {
protected function content() {
$accountID = ( isset( $_GET['accountID'] ) ? $_GET['accountID'] : 0 );
$query = "SELECT courseName FROM courses";
$result = query($query);
if($result->num_rows > 0) {
$temp = $result->fetch_assoc();
}
else {
echo "we have no data";
exit;
}
?>
<h1>Select a Course to Add</h1>
<div id="messageBox"></div>
<form id="addCoursePageForm" method="POST" action="_addCoursePage.php?accountID=<?php echo $accountID;?>">
<table>
<tr>
<td>Course 1</td>
<td>
<select>
<?php
$query = "SELECT * FROM courses";
$result = query($query);
for($i=0; $i < $result->num_rows; $i++) {
$temp2 = $result->fetch_assoc();
echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Course 2</td>
<td>
<select>
<?php
$query = "SELECT * FROM courses";
$result = query($query);
for($i=0; $i < $result->num_rows; $i++) {
$temp2 = $result->fetch_assoc();
echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Course 3</td>
<td>
<select>
<?php
$query = "SELECT * FROM courses";
$result = query($query);
for($i=0; $i < $result->num_rows; $i++) {
$temp2 = $result->fetch_assoc();
echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Course 4</td>
<td>
<select>
<?php
$query = "SELECT * FROM courses";
$result = query($query);
for($i=0; $i < $result->num_rows; $i++) {
$temp2 = $result->fetch_assoc();
echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Course 5</td>
<td>
<select>
<?php
$query = "SELECT * FROM courses";
$result = query($query);
for($i=0; $i < $result->num_rows; $i++) {
$temp2 = $result->fetch_assoc();
echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Course 6</td>
<td>
<select>
<?php
$query = "SELECT * FROM courses";
$result = query($query);
for($i=0; $i < $result->num_rows; $i++) {
$temp2 = $result->fetch_assoc();
echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Course 7</td>
<td>
<select>
<?php
$query = "SELECT * FROM courses";
$result = query($query);
for($i=0; $i < $result->num_rows; $i++) {
$temp2 = $result->fetch_assoc();
echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>";
}
?>
</select>
</td>
</tr>
<td> </td>
<td><input type="submit" value="Add Courses!" /></td>
</tr>
</table>
</form>
<?php
}
}
?>