单击后查看新页面中单行MySQL表的详细信息

时间:2014-05-07 11:21:20

标签: php mysql

我有一个显示MySQL数据库中所有工作的页面。

这是代码:

<?php


$result = mysqli_query($conn,"SELECT * FROM job ORDER BY `CreatedTime` DESC");


echo "<table border='0' cellpadding='0' cellspacing='0' class='table-fill'> 
<tr>
<th width='250px' position='fixed'>Job Title</th> 
<th width='150px'>Company Name</th>
<th width='100px'>Location</th>
<th>Closing Date</th>
</tr>";

while($row = mysqli_fetch_array($result) ) {
echo "<tr>";
echo "<td>" . $row['positiontitle'] . "</td>";
echo "<td>" . $row['companyname'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['closingdate'] . "</td>";

echo "</tr>";
}

echo "</table>";

mysqli_close($conn);
?>

我希望当我点击表格中的某个作业时,它应该在新页面中显示整个信息。

感谢

2 个答案:

答案 0 :(得分:0)

在表格中再添加一行

<th>View Job</th>

您的代码:

$result = mysqli_query($conn,"SELECT * FROM job ORDER BY `CreatedTime` DESC");


echo "<table border='0' cellpadding='0' cellspacing='0' class='table-fill'> 
<tr>
<th width='250px' position='fixed'>Job Title</th> 
<th width='150px'>Company Name</th>
<th width='100px'>Location</th>
<th>Closing Date</th>
<th>View Job</th>
</tr>";


while($row = mysqli_fetch_array($result) ) {
echo "<tr>";
echo "<td>" . $row['positiontitle'] . "</td>";
echo "<td>" . $row['companyname'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['closingdate'] . "</td>";
echo "<td><a href='job_details.php?id=".$row['job_id']."'>View Job</td>";

echo "</tr>";
}

在job_details.php中,根据id获取详细信息,并在该页面上显示结果。

jobdetails.php:

<?php

   $result = mysqli_query($conn,"SELECT * FROM job WHERE job_id = '".$_GET['id']."' ORDER BY `CreatedTime` DESC");

   $jobdetails = mysqli_fetch_assoc($result);

   echo 'Position : '.$jobdetails['positiontitle'].'<br>';
   echo 'Company Name: '.$jobdetails['companyname'].'<br>';
   echo 'Location: '.$jobdetails['location'].'<br>';
   echo 'Closing Date: '.$jobdetails['closingdate'].'<br>';


?>

答案 1 :(得分:0)

您还可以使用此id =代替id =“。$ row ['job_id']。”