user1783675
user1783675

Reputation: 356

Display data with the same id from a database

I have a table called workdetails. I have a foreign key called personid to identify all the work details belonging to the same person. The qualificationdetails table consist of the following Fields:

When the user completes a form, s/he will submit as many qualifications as they wish. Now I would like to Retrieve this data and display it on a web page. The following is the php code at the top of the page:

<?php
//Start the session
session_start();
//Connect to the database
require 'scripts/connect.php';
//Get the Person id
$persid = $_GET['Personid'];
//Select Applicant information from the tables
$Personid_query ="SELECT * FROM person where Personid=$persid";
$Qualification_query ="SELECT *FROM qualifications where Personid=$persid";

//Submit the selected information into the database
$Personid = mysql_query($Personid_query) or die(mysql_error);

$Qualificationid = mysql_query($Qualification_query) or die(mysql_error);

//Fetch the Applicant data
$row = mysql_fetch_assoc($Personid);
$QDrow = mysql_fetch_assoc($Qualificationid);
//I need to have another look at this one as well

?>

The following code is within the html tags


Qualification Name:

                                <hr width ="50%" />
                              <table border="0">
                              <!-- Display Qualification details-->
                              <tr>
                              <td><strong>Institution Name:</strong></td>
                              <td><?php echo $QDrow['InstitutionName'];?><br/></td>
                              </tr>
                              <tr>
                              <td><strong>Year Completed:</strong></td>
                              <td><?php echo $QDrow['CompletionYear'];?><br/></td>
                              </tr>

But the problem is that this above code only displays one Record, BUT I would like to display a Recoroder per person. for example


Upvotes: 2

Views: 1776

Answers (2)

lvil
lvil

Reputation: 4326

Why not to use JOIN

 $query ="SELECT * FROM person INNER JOIN qualifications ON   
person.Personid=qualifications.Personid where Personid=$persid";

Upvotes: 1

Sanjay
Sanjay

Reputation: 781

There a a number of qualification to a person, so you need to show all the qualifications

please try this

while($QDrow = mysql_fetch_array($Qualificationid)){
?>  
<tr>
   <td><strong>Institution Name:</strong></td>
   <td><?php echo $QDrow['InstitutionName'];?><br/></td>
   </tr>
   <tr>
   <td><strong>Year Completed:</strong></td>
   <td><?php echo $QDrow['CompletionYear'];?><br/></td>
 </tr>    
<?php
}

Upvotes: 0

Related Questions