使用MySQL / PHP信息返回ID

时间:2011-02-13 18:44:37

标签: php mysql

$sql  = 'SELECT `name`, `course`, `id` FROM `teacher`';
$rows = $mysql_conn->fetch_array($sql);
foreach($rows as $record) {
    $search_results[$record['name']] = $record['course'];
}

foreach($search_results as $teacher=>$string_courses){
    $array_courses = explode('-',$string_courses);
    $search_results[$teacher] = $array_courses;
}

foreach($search_results as $teacher=>$courses){
    foreach($courses as $period => $course){
        if($course == $id) {
            $name               = explode(',', $teacher);
            $results[$period][] = '<a href="?page=teacher&id='.ID HERE.'">'.$name[0].'<br />'.$name[1].'</a>';
        }
    }
}

如果在这里说出ID,我希望为每位教师插入返回的ID,但我不知道如何插入它以便它通过。

1 个答案:

答案 0 :(得分:2)

您正在以奇怪的方式构建数组,使用$record['name']作为键,将其更改为$record['id']并且您有更好的开始。