我有一个名为workdetails的表。我有一个名为personid的外键来识别属于同一个人的所有工作细节。 qualifieddetails表由以下字段组成:
当用户填写表格时,他/她将提交任意数量的资格。现在我想检索这些数据并将其显示在网页上。以下是页面顶部的php代码:
<?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
&GT;
以下代码位于html标记内
资格名称:
<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>
但问题是上面的代码只显示一个记录,但我想每个人显示一个Recoroder。例如
答案 0 :(得分:1)
为什么不使用JOIN
$query ="SELECT * FROM person INNER JOIN qualifications ON
person.Personid=qualifications.Personid where Personid=$persid";
答案 1 :(得分:0)
对一个人有一定的资格,所以你需要显示所有资格
请试试这个
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
}