我正在尝试从表中的每一行获取id,以便我能够更新不同页面上表单中的每条记录。不过,我一直试图从表中获得第一张唱片。有人可以提供一些帮助。
<div class="personnel_title">Personnel<br><hr>
<div class="addcontain">
<form method="post" action="">
<a href="HR_core_addpersonnel.php"><input type="button" name="addpersonnel" value="Add"></a>
</form>
<div class="searchcontain">
<form method="post" action="HR_core_personnel.php">
<input type="text" id="search" name="search" placeholder="Search" /><br>
</form>
<div id="output">
</div>
</div>
</div>
<hr>
<?php
$query = "SELECT `fighterID`, `firstName`, `middleName`, `lastName`, `rank`.`rank`, `status`, `telephone1`, `telephone2`, `stationlocation`.`exactlocation`, `hireDate`, `workShift`
FROM `firefighterinfo`
JOIN `rank` ON `firefighterinfo`.`Rank_rankID` = `rank`.`rankID`
JOIN `stationlocation` ON `firefighterinfo`.`StationLocation_locationID` = `stationlocation`.`locationID`";
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();
?>
<div class="results_table">
<table>
<thead>
<tr>
<th>Firefighter</th>
<th>Rank</th>
<th>Status</th>
<th>Home No.</th>
<th>Cell No.</th>
<th>Station</th>
<th>Hire Date</th>
<th>Shift</th>
<th></th>
</tr>
</thead>
<?php
$i = 0;
while($i < $num){
$f1 = mysql_result($result, $i, 'firstName');
$f2 = mysql_result($result, $i, 'middleName');
$f3 = mysql_result($result, $i, 'lastName');
$f4 = mysql_result($result, $i, 'rank');
$f5 = mysql_result($result, $i, 'status');
$f6 = mysql_result($result, $i, 'telephone1');
$f7 = mysql_result($result, $i, 'telephone2');
$f8 = mysql_result($result, $i, 'exactlocation');
$f9 = mysql_result($result, $i, 'hireDate');
$f10 = mysql_result($result, $i, 'workShift');
?>
<tbody id="table_body">
<tr>
<td>
<?php echo $f1; ?>
<?php echo $f2; ?>
<?php echo $f3; ?>
</td>
<td>
<?php echo $f4; ?>
</td>
<td>
<?php echo $f5; ?>
</td>
<td>
<?php echo $f6; ?>
</td>
<td>
<?php echo $f7; ?>
</td>
<td>
<?php echo $f8; ?>
</td>
<td>
<?php echo $f9; ?>
</td>
<td>
<?php echo $f10; ?>
</td>
<td>
<a href="HR_core_updatepersonnel.php>"><img src="images/Awicons-Vista-Artistic-Edit.ico" width="15" height="20" alt="Edit"></a>
</td>
</tr>
</tbody>
<?php
$i++;
}
?>
</table>
</div>
</div>
答案 0 :(得分:1)
@Farman给你一个很好的答案,这是我的一些补充
mysql_result
改为性能更佳的电话fighterID
为正确的密钥 <div class="personnel_title">Personnel<br><hr>
<div class="addcontain">
<form method="post" action="">
<a href="HR_core_addpersonnel.php"><input type="button" name="addpersonnel" value="Add"></a>
</form>
<div class="searchcontain">
<form method="post" action="HR_core_personnel.php">
<input type="text" id="search" name="search" placeholder="Search" /><br>
</form>
<div id="output"></div>
</div>
</div>
<hr>
<?php
$query = "SELECT `fighterID`, `firstName`, `middleName`, `lastName`,
`rank`.`rank`, `status`, `telephone1`, `telephone2`,
`stationlocation`.`exactlocation`, `hireDate`, `workShift`
FROM `firefighterinfo`
JOIN `rank` ON `firefighterinfo`.`Rank_rankID` = `rank`.`rankID`
JOIN `stationlocation` ON `firefighterinfo`.`StationLocation_locationID` = `stationlocation`.`locationID`";
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();
?>
<div class="results_table">
<table>
<thead>
<tr>
<th>Firefighter</th>
<th>Rank</th>
<th>Status</th>
<th>Home No.</th>
<th>Cell No.</th>
<th>Station</th>
<th>Hire Date</th>
<th>Shift</th>
<th> </th>
</tr>
</thead>
<?php
$c = array('fighterID','firstName','middleName','lastName','rank','status','telephone1','telephone2','exactlocation','hireDate','workShift');
while($r = mysql_fetch_assoc($result)) { ?>
<tbody id="table_body">
<tr>
<td><?php echo $r[$c[1]].' '.$r[$c[2]].' '.$r[$c[3]]; ?></td>
<td><?php echo $r[$c[4]]; ?></td>
<td><?php echo $r[$c[5]]; ?></td>
<td><?php echo $r[$c[6]]; ?></td>
<td><?php echo $r[$c[7]]; ?></td>
<td><?php echo $r[$c[8]]; ?></td>
<td><?php echo $r[$c[9]]; ?></td>
<td><?php echo $r[$c[10]]; ?></td>
<td>
<!-- the change made by @Farman Ullah is here -->
<a href="HR_core_updatepersonnel.php?fighterID=<?php echo $r[$c[0]]; ?>">
<img src="images/Awicons-Vista-Artistic-Edit.ico" width="15" height="20" alt="Edit">
</a>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
</div>
随时提出任何问题或添加反馈