Passing value through series of arrays
I've asked this question before but the answers were not significant to assisting me.
$sql = 'SELECT `name`, `course`, `id` FROM `teacher` ORDER BY `id` ASC';
$rows = $mysql_conn->fetch_array($sql);
// Teacher's Table (id / name / link /course)
// Course default = 1-1-1-1-1-1-1-1
foreach($rows as $record) {
$result[$record['name']] = $record['course'];
//$result["Moore,Tyler"] = "1-1-1-1-1-1-1-1";
//$result["Craig,Joey"] = "1-2-2-2-1-1-1-1";
//$result["Degra,Tina"] = "2-1-1-1-2-1-1-1";
}
foreach($result as $teacher=>$courses){
$result[$teacher] = explode('-',$courses); // Remove -'s from courses and separate the array into sections
//$result["Craig,Joey"][0] = 1;
//$result["Craig,Joey"][1] = 2;
//$result["Craig,Joey"][2] = 2;
//$result["Craig,Joey"][3] = 2;
//$result["Craig,Joey"][4] = 1;
//$result["Craig,Joey"][5] = 1;
//$result开发者_如何转开发["Craig,Joey"][6] = 1;
//$result["Craig,Joey"][7] = 1;
}
foreach($result as $teacher=>$courses){
foreach($courses as $period => $course){
if($course == $id) { // If course is equal to course page (selected course) record the period 1-8
$name = explode(',', $teacher); // $name[0] = 'Craig' / $name[1] = 'Joey';
$result[$period][] = '<a href="?page=teacher&id=">'.$name[0].'<br />'.$name[1].'</a>';
// I want id= to get an id passed to it from the query
}
}
}
I want to have the teacher's ID passed through so I can feature it into the link near the bottom of the code.
This is absolutely necessary however I can not seem to figure it all out without my head hurting.
Any help would be much appreciated! :)
I would add the teacher ID to their name:
$sql = 'SELECT CONCAT(`name`, ",", `id`) AS `name`, `course` FROM `teacher` ORDER BY `id` ASC';
and then when you explode the teacher's name you will have their ID on index 2
(last name, first name, ID).
精彩评论