基本上,我有一个包含学生日程安排的数据库。每个课时都有自己的栏目。我想返回在特定时期内具有特定类别的每个用户的每个名称。
这是我当前的代码。唯一的问题是代码只返回它找到的第一个名字,而不是每个具有相同类的人。
if ($test_stmt=$mysqli->prepare("SELECT cps_schedules_userid FROM cps_schedules WHERE monday=?")) { //Get user's ids with same class in same period
$test_stmt->bind_param('s',$classarray_withperiod[$i]); //Bind parameters (class name)
$test_stmt->execute(); //Execute the prepared query
$test_stmt->store_result(); //Store result
if ($test_stmt->num_rows()<=1) { //0 or 1 rows were returned, meaning that only the current user has this class
}
else { //Other people have the class, so the query returned values
$entirerowdata = array(); //Create array to hold all data in returned row
stmt_bind_assoc($test_stmt, $entirerowdata); //Get all values in row
$arrayofusernames=array(); //Create array to hold names of all the users
$arrayofusernamesindex=0;
while ($test_stmt->fetch()) {
//Convert userid -> username
$arrayofusernames[$arrayofusernamesindex]=$entirerowdata['cps_members_username'];
$arrayofusernamesindex++;
}
}
}
这是我的 cps_schedules 数据库的快照。它基本上向右移动,直到到达 "friday7" :