之前我曾问过这个问题,但答案并不重要,无法帮助我。
$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
}
}
}
我想让老师的ID通过,所以我可以把它放在代码底部附近的链接中。
这绝对是必要的,但是如果没有我的头疼,我似乎无法全部解决这个问题。
任何帮助将不胜感激! :)
答案 0 :(得分:1)
我会将教师ID添加到他们的名字中:
$sql = 'SELECT CONCAT(`name`, ",", `id`) AS `name`, `course` FROM `teacher` ORDER BY `id` ASC';
然后当您分解教师姓名时,您将在索引2
(姓氏,名字,身份证)上获得他们的ID。