我有两个表job
,其中包含一个名为employer_id_job
的属性,将其链接到employer
表。我可以使用PHP使用以下代码在表中显示job
的内容
<?php
$query = "SELECT * FROM job";
$result = mysql_query($query);
$num = mysql_numrows($result);
$count = 0;
while ($count < $num)
{
$title = mysql_result ($result, $count, "Title");
$date_posted = mysql_result ($result, $count, "Date_posted");
$application_deadline = mysql_result ($result, $count, "Application_deadline");
$description = mysql_result ($result, $count, "Description");
$years_of_experience = mysql_result ($result, $count, "Years_of_experience");
$education_level = mysql_result ($result, $count, "Education_level_required");
$contract = mysql_result ($result, $count, "Contract_type");
$company = mysql_result ($result, $count, "Company_name");
?>
<tr>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $count + 1; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $title; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $company; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $description; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $date_posted; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $application_deadline; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $education_level; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $years_of_experience; ?></font></td>
<td><font face = "Arial, Helvetica, sans-serif"><? echo $contract; ?></font></td>
<?
$count ++;
}
?>
我在尝试为$company
变量赋值时将此方法分解,该变量保存在employer
表中。我的假设只是使用与其余变量相同的表示法将导致脚本跟随employer
表的外键并在那里获取属性,但它没有这样做。
我应该如何访问通过外键相关的表的内容?
答案 0 :(得分:1)
select * from job as j, company as c where j.company == c.company
我不确定你的田地名称是什么,所以我做了最好的猜测。这允许您访问这两个字段。