$Query="select SubCode,SubLongName from subjects where sem=1"; $Subject=mysqli_query($con,$Query); $i=-1; while($row = mysqli_fetch_array($Subject)) { $i++; $SubjectCode[$i]['SubCode']=$row['SubCode']; $SubjectCode[$i]['SubLongName']=$row['SubLongName']; }
Here, the while loop will retrieve each row. All columns of the row will be stored in the variable $row (array), but when the next iteration happens, it will be lost. Therefore, we copy the contents of the $row array into a multidimensional array called $SubjectCode . The contents of each row will be stored in the first index of this array. This can be used later in our script. (I'm new to PHP, so if anyone came across this who knows a better way, write about it along with a comment with my name so that I can find out new.)
Nidhin david
source share