I'm new to PHP and now I have some problems about the logic to query the data from my database.
First if I have 2 databases which are Application file and Position file.
Application file includes
- Application_ID, 2.Applicant_ID, 3.Position_ID
and Position file includes
1.Position_ID, 2.Position_Name, 3.Department_Name
Let me show the unfinished codes...
Link (I copy everything in HTML provided field) -> https://jsfiddle.net/2e50wvzq/
I would like to focus here...
$result4 = mysql_query("SELECT * FROM position");
while ($rows4 = mysql_fetch_array($result4, MYSQL_ASSOC)){
$pos_dept = $rows4['Position_Department'];
$result5 = mysql_query("SELECT * FROM position WHERE Position_Department = '".$pos_dept."' ");
while($rows5 = mysql_fetch_array($result5, MYSQL_ASSOC)){
$pos_id = $rows5['Position_ID'];
}
for($i = 0; $i < $counter; $i++){
if($dept_array[$i] == $pos_dept){
}else{
$result6 = mysql_query("SELECT App_Data_ID FROM application_data_file WHERE Position_ID = '".$pos_id."' ");
$pos_app = 0;
while ($rows6= mysql_fetch_array($result6, MYSQL_ASSOC)){
$pos_a = $rows6['App_Data_ID'];
$pos_app++;
}
array_push($dept_array," '".$pos_dept."' ");
?>
<TR>
<TD> <?php echo $rows4['Position_Department']; ?> </TD>
<TD> <?php echo $rows4['Recruitment_Seat']; ?> </TD>
<TD> <?php echo $pos_app; ?> </TD>
<TD> <?php echo $recruited; ?> </TD>
<TD> <?php echo $Vacancy; ?> </TD>
</TR>
<?php
}
}
}
?>
Assume that the data in databases are state as...
Application File
00001, 00001, 00001
00002, 00003, 00001
00003, 00002, 00002
00004, 00004, 00001
00005, 00006, 00002
and Position File
00001, Programmer, Department of IT
00002, Accountant, Department of Accounting
As my codes, the result in the table should be as this picture (focus in "Total Applicants" tab in the first table)
From my thinking so far, if I use the codes as I posted above the result will turn to be like table 2 (or maybe similar).
How can I provide the result like table 1 result? Please help.
