简体   繁体   中英

Query data from multiple database tables into form table (MYSQL,PHP)

As I'm new to PHP, I want to know that how to put data from different database tables into one table form on the page. My codes so far as below,

<?php


include('DBconnect.php');
mysql_query("USE onlinerecruitment");

$username =$_SESSION['user'];

$result = mysql_query("SELECT * FROM application_data_file");

$rows = mysql_fetch_array($result, MYSQL_ASSOC);

$pos_id = $rows['Position_ID'];

$resultt = mysql_query("SELECT * FROM position WHERE Position_ID = '".$pos_id."' ");

$resulttt = mysql_query("SELECT * FROM resume_data_file WHERE App_Email = '".$pos_id."' ");

?>

<TABLE border ='1'>
<table style="width:100%">
<tr>

<th>Application ID</th>
<th>Applicant E-mail</th>
<th>Position Selected</th>
<th></th>
<th></th>
<th></th>

</tr>

<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) &  $rowss = mysql_fetch_array($resultt, MYSQL_ASSOC)){

echo "<TR>";

echo "<TD>".$row['App_Data_ID']."</TD>";
echo "<TD>".$row['App_Email']."</TD>";
echo "<TD>".$rowss['Position_Name']."</TD>";
echo "<TD><a href='view-app-form.php?app_mail=".$row['App_Email']."'>View Application Data</a></TD>";
echo "<TD><a href='view-resume-form.php?app_mail=".$row['App_Email']."'>View Resume Data</a></TD>";
echo "<TD><a href='view-test-score.php?app_mail=".$row['App_Email']."'>View Testing Score Data</a></TD>";

echo "</TR>";
}

?>
</table>

I will focus the part here.

<TABLE border ='1'>
<table style="width:100%">
<tr>

<th>Application ID</th>
<th>Applicant E-mail</th>
<th>Position Selected</th>
<th></th>
<th></th>
<th></th>

</tr>

<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) &  $rowss = mysql_fetch_array($resultt, MYSQL_ASSOC)){

echo "<TR>";

echo "<TD>".$row['App_Data_ID']."</TD>";
echo "<TD>".$row['App_Email']."</TD>";
echo "<TD>".$rowss['Position_Name']."</TD>";
echo "<TD><a href='view-app-form.php?app_mail=".$row['App_Email']."'>View Application Data</a></TD>";
echo "<TD><a href='view-resume-form.php?app_mail=".$row['App_Email']."'>View Resume Data</a></TD>";
echo "<TD><a href='view-test-score.php?app_mail=".$row['App_Email']."'>View Testing Score Data</a></TD>";

echo "</TR>";
}

?>
</table>

But if there is any problem in the section that I didn't focused, I still appreciate your solution.

Thank you in advance.

To do this you would need to use a JOIN in the sql statement.

mysql_query("SELECT resume_data_file.App_Email, position.Position_ID FROM position INNER JOIN resume_data_file ON position.Position_ID = position.Position_ID  WHERE position.Position_ID = '".$pos_id."'   ");

http://www.w3schools.com/sql/sql_join.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM