Here i have a query to my MySql database and I am taking out all the information about a course to be put in a row and displayed in my table. The last column of the table is a check box, that check box I want to make it so it will save the row of data for each row that it is checked off. The variable i chosen was courses[], to be saved in array then saved in session to be accessed else where. I’m not sure how to extract the row data to put in to my array. Right now I have value='$row2013 and that doesnt work because when I var_dump($courses) = array(5) { [0]=> string(5) "Array" [1]=> string(5) "Array" [2]=> string(5) "Array" [3]=> string(5) "Array" [4]=> string(5) "Array" } , Which I have selected five courses.
To sum things up, I am not saving the right thing.
case 2013:
$string2013 = "SELECT Course.CourseCode, Course.Title, Course.WeeklyHours, Semester.Term, Semester.SemesterCode
FROM Course, CourseOffer, Semester WHERE Semester.YearNum='$selectedYear' AND Course.CourseCode=CourseOffer.CourseCode AND
Semester.SemesterCode=CourseOffer.SemesterCode";
if($Result2013 = mysqli_query($link, $string2013))
{
echo "<form action='CourseSelection.php' method='get'>
<table><tr><th>Code</th><th>Course Title</th><th>Hours</th><th>Term</th><th>Select</th></tr>";
while($row2013 = mysqli_fetch_assoc($Result2013))
{
echo "<tr><td>$row2013[CourseCode]</td><td>$row2013[Title]</td><td>$row2013[WeeklyHours]</td>
<td>$row2013[Term]</td><td><input type='checkbox' name='courses[]' value='$row2013'></td></tr>";
}
echo "</table>";
}
else
{
echo "<p>" + mysqli_error($link) + "</p>";
}
break;
You should try to save only the row ID in the value of checkbox. This way you can easily recall a row from the database by its ID.
$row2013["CourseCode"]should work.When you do the POST request, you will get an array of IDs (
$_POST['courses']). Of course you need to treat it as array, so you must iterate over it in order to get all the rows you selected.If you
var_dump($_POST['courses'])you should see something like this, assuming you have selected the first 5 rows:Now just query the database according to the selected rows, and you’re good to go: