Basically, I have a database with students's schedules. Each class period has its own column. I want to return every name of every user that has a certain class in a certain period.
Here is my current code. The only problem is that the code only returns the first name it finds, and not everyone with the same class.
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++;
}
}
}
This is a snapshot of my cps_schedules database. It essentially goes on to the right until it reaches "friday7" :