Anthony Galpo Anthony Galpo - 7 months ago 16
PHP Question

How to get the specific array data from and array in php and store it

I have this php code to select studentid's from database table and print out the students with value 1 in the Project1 column.

<?PHP
include_once("connectionToProjectChoice.php");
/* Check column 1 (Project1) in tbl_studentchoice*/
$check = "SELECT * FROM tbl_studentchoice WHERE Project1 = '1'";
$result = mysqli_query($conn, $check);

if ($result->num_rows > 0){ //check
$student = array();
while($row = mysqli_fetch_assoc($result)) {
$array[$row['studentid']]=$row['Project1'];
}
}
print_r($array);
?>


The result I get is Result

So my question is is there a way I could store studentname(c125582333) and (c12558242)separately so I could make an If statement because I want to compare them in the next section of the code.

Answer
 if ($result->num_rows > 0){ //check
        $student = array();
        while($row = mysqli_fetch_assoc($result)) {
            $array[] = [
                  'studentid' => $row['studentid']],
                  'Project1' => $row['Project1']
           ];
        }   
  }
  print_r($array);  

It might be easier building your array differently?