SQL PHP选择具有某些数据的每个用户

时间:2013-08-08 21:08:17

标签: php sql database select

基本上,我有一个包含学生日程安排的数据库。每个课时都有自己的专栏。我想返回在某段时间内具有某个类的每个用户的每个名字。

这是我目前的代码。唯一的问题是代码只返回它找到的第一个名字,而不是每个具有相同类的人。

            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数据库的快照。它基本上是向右走,直到达到“星期五7”:

Snapshot of database

0 个答案:

没有答案