gpt4 book ai didi

php - 通过一系列数组传递值

转载 作者:行者123 更新时间:2023-11-29 14:54:28 25 4
gpt4 key购买 nike

我以前问过这个问题,但答案对我帮助不大。

    $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,以便我可以将其添加到代码底部附近的链接中。

这是绝对必要的,但我似乎无法在不头痛的情况下弄清楚这一切。

任何帮助将不胜感激! :)

最佳答案

我会将教师 ID 添加到他们的名字中:

$sql  = 'SELECT CONCAT(`name`, ",", `id`) AS `name`, `course` FROM `teacher` ORDER BY `id` ASC';

然后,当您分解老师的姓名时,您将在索引 2 中找到他们的 ID(姓氏、名字、ID)。

关于php - 通过一系列数组传递值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4986889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com