Link to home
Start Free TrialLog in
Avatar of Akhil Vinay Mandava
Akhil Vinay MandavaFlag for India

asked on

Problem in fetching

please look attached file.i need to print the data individulaly
i created two tabular forms in phpmyadmin those two are linked data is fetching here the problem is while fetching the data i'm getting the employess data continusly.
for example : i created two tables one is employee family and other one is employee personal.while fetching the data all employees family details are fetching at a time similarly personal details comming like that but i want in order
<h3 style="font-size:10%;"><h3 style="text-align:center;color:black;">EMPLOYEE INFORMATION</h3>
<?php
 $dbhost = "localhost";
 $dbuser = "GCSADMIN";
 $dbpass = "123456";
 $db = "employee_db";

    $conn = mysql_connect($dbhost, $dbuser, $dbpass,$db);

   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }

   $sql = "SELECT EmployeeID,FirstName,MiddleName,LastName,FatherName,SpouseName,MotherName,DOB,Age,BloodGroup,MaritalStatus,Gender,ContactNumber,EmergencyContactNumber,Email,DateOfJoiningatGemini,TotalYearOfExperience,ReleventYearOfExperience,PANnumber,PassportNumber,UANnumber,AadharNumber,PresentAddress,PermanentAddress FROM employee_information";

   mysql_select_db('employee_db');
   $retval = mysql_query( $sql, $conn );
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   }
   
   echo "<table border='5px solid block', align='center', width='50%', padding='12px 20px' >";

   while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC)){

     ?>
     
            <tr><th align="left">Employee ID</th><td><?php echo $row['EmployeeID']; ?></td></tr>
            <tr><th align="left">First Name</th><td><?php echo $row['FirstName']; ?></td></tr>
            <tr><th align="left">Middle Name</th><td><?php echo $row['MiddleName']; ?></td> </tr>
            <tr><th align="left">Last Name</th><td><?php echo $row['LastName']; ?></td></tr>
            <tr><th align="left">Father's Name </th><td><?php echo $row['FatherName']; ?></td> </tr>
            <tr><th align="left">Mother's Name </th><td><?php echo $row['MotherName']; ?></td> </tr>
            <tr><th align="left">Spouse Name </th><td><?php echo $row['SpouseName']; ?></td> </tr>
            <tr><th align="left"> Date of Birth </th><td><?php echo $row['DOB']; ?></td> </tr>
            <tr><th align="left">Age </th><td><?php echo $row['Age']; ?></td> </tr>
            <tr><th align="left">Blood Group </th><td><?php echo $row['BloodGroup']; ?></td> </tr>
            <tr><th align="left">Marital status </th><td><?php echo $row['MaritalStatus']; ?></td> </tr>
            <tr><th align="left">Gender </th><td><?php echo $row['Gender']; ?></td> </tr>
            <tr><th align="left">Contact Number </th><td><?php echo $row['ContactNumber']; ?></td> </tr>
            <tr><th align="left">Emergency Contact Number </th><td><?php echo $row['EmergencyContactNumber']; ?></td> </tr>
            <tr><th align="left">Email </th><td><?php echo $row['Email']; ?></td> </tr>
            <tr><th align="left">Date of Joining at Gemini </th><td><?php echo $row['DateOfJoiningatGemini']; ?></td> </tr>
            <tr><th align="left">Total Years of Experience </th><td><?php echo $row['TotalYearOfExperience']; ?></td> </tr>
            <tr><th align="left">Relevant Years of Experience </th><td><?php echo $row['ReleventYearOfExperience']; ?></td> </tr>
            <tr><th align="left">PAN number </th><td><?php echo $row['PANnumber']; ?></td> </tr>
            <tr><th align="left">Passport Number </th><td><?php echo $row['PassportNumber']; ?></td> </tr>
            <tr><th align="left">UAN number </th><td><?php echo $row['UANnumber']; ?></td> </tr>
            <tr><th align="left">Aadhar Number </th><td><?php echo $row['AadharNumber']; ?></td> </tr>
            <tr><th align="left">Present Address </th><td><?php echo $row['PresentAddress']; ?></td> </tr>
            <tr><th align="left">Permanent Address </th><td><?php echo $row['PermanentAddress']; ?></td> </tr>

        <?php 
        }
        echo "</table></br></br>";  


      $qry="SELECT EmployeeID,Qualification,YearOfPassing,University,Percentage FROM employee_qualifications" ;

      mysql_select_db('employee_db');
   $retval = mysql_query( $qry, $conn );
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   } 
   
   echo "<table border='5px solid block', align='center', width='50%', padding='12px 20px' >";
?>
<tr>
    <th>Qualification</th>
    <th>Year of Passing</th> 
    <th>University</th>
    <th>Percentage</th>
</tr>
<?php
     while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC))  { 
      ?>

   

      <tr>
            <td><?php echo $row['Qualification']; ?></td> 
            <td><?php echo $row['YearOfPassing']; ?></td> 
            <td><?php echo $row['University']; ?></td>
            <td><?php echo $row['Percentage']; ?></td> 
      </tr>

        <?php 
        }
         echo "</table></br></br>";  





   $qry="SELECT EmployeeID,Organization,Fro,Till FROM employee_orgnization";

      mysql_select_db('employee_db');
   $retval = mysql_query( $qry, $conn );
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   } 
   
   echo "<table border='5px solid block', align='center', width='50%', padding='12px 20px' >";
?>
<tr>
    <th>Organization</th>
    <th>From</th>
    <th>Till</th>

</tr>
<?php

     while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC))  { 
      ?>

  
      <tr>
            <td><?php echo $row['Organization']; ?></td> 
            <td><?php echo $row['Fro']; ?></td> 
            <td><?php echo $row['Till']; ?></td> 
      </tr> 
        
        <?php 
        }
         echo "</table></br></br>"; 




    $qry="SELECT EmployeeID,Name,Relationship,ag,Occupation FROM employee_family" ;

      mysql_select_db('employee_db');
   $retval = mysql_query( $qry, $conn );
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   } 
   
   echo "<table border='5px solid block', align='center', width='50%', padding='12px 20px' >";
?>
<tr>
    <th>Name</th>
    <th>Relationship</th>
    <th>Age(Years)</th> 
    <th>Occupation</th>
</tr>
<?php

     while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC))  { 
      ?>
  
      <tr>
            <td><?php echo $row['Name']; ?></td> 
            <td><?php echo $row['Relationship']; ?></td> 
            <td><?php echo $row['ag']; ?></td>
            <td><?php echo $row['Occupation']; ?></td> 
      </tr>
      
        
        <?php 
        }
         echo "</table>";               
  // echo "Fetched data successfully";
   mysql_close($conn);
?>

Open in new window

fetch1.html
Untitled.png
Avatar of Hugo Alves
Hugo Alves
Flag of Portugal image

Hello,

Sorry I don't understand what you are trying to do.
Your query:

SELECT EmployeeID,FirstName,MiddleName,LastName,FatherName,SpouseName,MotherName,DOB,Age,BloodGroup,MaritalStatus,Gender,ContactNumber,EmergencyContactNumber,Email,DateOfJoiningatGemini,TotalYearOfExperience,ReleventYearOfExperience,PANnumber,PassportNumber,UANnumber,AadharNumber,PresentAddress,PermanentAddress FROM employee_information

Open in new window


Retrieves the information for all employees.

Your next command is a "while" that writes all the data retrieved by the query:

while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC)){
...
}

Open in new window


You, either need to retrieve the information for a single employee by using the "where" clause in the query, or you need to process a single employee at a time in the "while" loop.

Thank you
Avatar of Tomas Helgi Johannsson
Hi!

You have 4 queries. One for each table. One that one of them is the parent table and the others are child tables.
What you need to do is to formulate your logic and html buildup into a loop so that for each record in the parent table you print out the parent record and use the employeeid of the record to fetch from the other child tables using where clause.

In psudo code

$parent_sql = "SELECT EmployeeID,FirstName,MiddleName,LastName,FatherName,SpouseName,MotherName,DOB,Age,BloodGroup,MaritalStatus,Gender,ContactNumber,EmergencyContactNumber,Email,DateOfJoiningatGemini,TotalYearOfExperience,ReleventYearOfExperience,PANnumber,PassportNumber,UANnumber,AadharNumber,PresentAddress,PermanentAddress FROM employee_information";

while($parent_row = mysql_fetch_assoc($retval, MYSQL_ASSOC)){ 
print out parent record in html table

$childqry1="SELECT EmployeeID,Qualification,YearOfPassing,University,Percentage FROM employee_qualifications where employeeid = $parent_row['EmployeeID']" ;
print out childtable 1

$childqry2="SELECT EmployeeID,Organization,Fro,Till FROM employee_orgnization where employeeid = $parent_row['EmployeeID']" ;
print out childtable 2

$childqry3="SELECT EmployeeID,Name,Relationship,ag,Occupation FROM employee_family where employeeid = $parent_row['EmployeeID']" ;
print out childtable 3

}

Open in new window


Regards,
    Tomas Helgi
SOLUTION
Avatar of Akhil Vinay Mandava
Akhil Vinay Mandava
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Akhil Vinay Mandava

ASKER

good