I am trying to fetch three things from 2 different tables for each ID i.e for me RegID
My first query is to select
DISTINCT RegID from table_oneif there are more than one it should select all in whereAttendanceStatus =AbsentandAttendanceDate = Todays_datefor each
RegIDselected it should selectDISTINCT SubjectsandStandardfrom sametable_one- the same id it should select mobile number from
table_twoand it should echo then repeat for secondRegIDif exist the same should be repeated until lastRegID
i am getting the DISTINCT regid but in the same while statement if am using the fetch result to get subject and standard along with register id it give me only one id , subject and standard and am not getting how to solve this
My EDIT
Now in my example database i have two entries that says absent in AttendanceStatus so in my first select i vl remove duplicate if exist and select those 2RegID that is working fine now for that each RegID i want to select Standard and subject in my second query that is in while statement tough there are two RegID it is giving me only one i need those two absent reg to be shown up along with there respective distinct subject and standards
To be simple
- First
RegIDselect who ever are absent by removing duplicate - Select
StandardandSubjectsfor the first selectedRegID's - Echo separately
RegID,StandardandSubjectsfor eachRegID
My table_one data base
AttendanceDate Standard Subjects RegID AttendanceStatus
2016-01-08 00:00:00 III BSc PCM PHY/CHEM PRACTICAL 1382043 Present
2016-01-08 00:00:00 III BSc PCM PHY/CHEM PRACTICAL 1382044 Present
2016-01-08 00:00:00 III BSc PCM PHY/CHEM PRACTICAL 1382045 Present
2016-01-08 00:00:00 III BSc PCM PHY/CHEM PRACTICAL 1382046 Absent
2016-01-08 00:00:00 III BSc PCM PHY/CHEM PRACTICAL 1382047 Absent
PHP Mysqli code
$query="SELECT DISTINCT RegID FROM table_one WHERE AttendanceDate='2016-01-08 00:00:00' and AttendanceStatus='Absent'" ;
$data=mysqli_query($mysqli,$query)or die(mysqli_error());
if(mysqli_num_rows($data) > 0) {
while($row=mysqli_fetch_array($data)){
$StudentRegID= $row['RegID'];
$query="SELECT DISTINCT(CONCAT(Standard,Subjects)) AS standard_and_subject , RegID FROM table_one WHERE AttendanceDate='2016-01-08 00:00:00' and RegID='$StudentRegID'" ;
$data=mysqli_query($mysqli,$query)or die(mysqli_error());
if(mysqli_num_rows($data) > 0) {
while($row=mysqli_fetch_array($data)){
if($row['RegID'] != '' && $row['RegID'] != NULL){
$RegID = $row['RegID'];
$standard_and_subject = $row['standard_and_subject'];
echo $standard_and_subject;
echo $RegID;
}
}
}
}
}