I am initialize a array variable out of while loop and issue is that when this array variable is print out of the while loop then array is not show and when this array variable is print within the loop then array is show.
<?php
$all_rollno="";
//Get Current Session
$Res_Sess = mysql_query("SELECT sessionid from tbl_session where status=1 ORDER BY sessionid desc limit 1");
$Row_Sess = mysql_fetch_array($Res_Sess);
$Session = $Row_Sess[0];
//Get Batch
$Res_Bat = mysql_query("SELECT batchid,batchname,code FROM tbl_batch where status=1 and batchid!=12 ORDER BY batchid asc");
while($Row_Bat = mysql_fetch_array($Res_Bat)){
$Batch = $Row_Bat['batchid'];
$Bat_Code = $Row_Bat['code'];
//Present - Attendance
$Patt4 = mysql_query("select count(id),rollno from tbl_attendance where batchid = '$Batch' and sessionid = '$Session' and attend = 1 GROUP by rollno");
$arraytpresent="";
$array_rollno="";
$ipresent=0;
while($Row_P4 = mysql_fetch_array($Patt4)){
$arraytpresent[$ipresent] = round(($Row_P4[0]/$maxValue*100),0);
$array_rollno[$ipresent] = $Row_P4[1];
$ipresent++;
}
if(sizeof($all_rollno)>0){
$all_rollno = array_merge($all_rollno,$array_rollno);
} else {
$all_rollno = $array_rollno;
}
//print_r($all_rollno);
}
print_r($all_rollno);
mysql_
calls. Mission #1: Avoid executing queries in a loop.all_rollno
as empty string, why? why not as empty array? Same goes for$array_rollno
...