Returning ID with information MySQL/PHP
$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>';
}
}
}
Where it says ID HERE, I want the ID returned for each teacher inserted there but I do not know how to insert it so that it passes through.
You're building your array in a weird way, using $record['name']
as a key, change that to $record['id']
and you have a better start.
精彩评论