Storing values from SQL tables into different PHP arrays

时间:2019-04-17 02:01:52

标签: javascript php html mysql

In my course_status table. I have 3 columns(course_name, course_status, student_id). When I searched for a student id, the course_name cell table should change according to the status. This is the query I am using to get pending, completed and incomplete courses into my arrays.

$done_course = array();
$progress_course = array();
$pending_course = array();
 while($row2 = mysqli_fetch_assoc($retval2)){
        if($row2['course_status'] = 'pending') {
                $pending = True; 
                array_push($pending_course, $row2['course_name']);}
         if($row2['course_status'] = 'In_progress')  {
                $progress = True;                                                 
                 array_push($progress_course,$row2['course_name']); } 
          if($row2['course_status'] = 'done') {
                 $done = True; 
                 array_push($done_course, $row2['course_name']); }

My question is when I run the code $done_courses will store all courses including pending and incomplete. How do I prevent it and make it only store completed courses?

1 个答案:

答案 0 :(得分:1)

My question is when I run the code $done_courses will store all courses including pending and incomplete.

I don't think this was printing mistake if($row2['course_status'] = 'pending') { you are comparing with single = instead of ==

Once you change this = to this == it will work fine...