如何在php / mysql表中显示最后一次插入行ID的编辑按钮

时间:2014-02-19 13:07:52

标签: php html mysql

我在Php中有一个View Grid。在此编辑按钮(如操作编辑,删除图标)需要仅显示最后一个插入行。你能帮我看看如何显示。这是我的代码

<?php
$followup_details=mysql_query("select * from tbl_followup where school_id='$id' order by followup_id desc");
if(mysql_num_rows($followup_details))
{
?>
<form name="view-school" method="post" action="">
<table width="100%" border="0" cellspacing="1" cellpadding="1" class="table_txt">
  <tr class="table_txt2">
    <td width="7%">#</td>
        <td width="20%">Minutes Of Meeting</td>
    <td width="20%">Details</td>
    <td width="13%">Followup Status</td>
    <td width="10%">Next Meeting Date</td>
    <td width="10%">Actions</td>
  </tr>
  <?php
$slno=0;

while($followup=mysql_fetch_array($followup_details))
{
$slno++;

?>
<tr <?php if($slno%2==1) echo "class='table_txt3'"; else echo "class='table_txt4'"; ?>><td ><?php echo $slno;?></td>

<td ><?php echo ucwords($followup['mom']);?></td>
<td ><?php echo $followup['details'];?></td>
<td ><?php echo ucwords($followup['followup_status']);?></td>
<td ><?php echo $followup['next_meeting_date'];?></td>
 <td>
  <a href="#" class="edit-followup" data-reveal-id="editfollowup" data-animation="fade" id="<?php echo $followup['followup_id'];?>"><img src="images/edit_icon.png" alt="editicon" width="20" height="20" border="0" class="marg" /></a>

</td>
  <?php }
  ?>

我的编辑图标只需显示最后一个插入行。请帮我。提前致谢

4 个答案:

答案 0 :(得分:0)

可能是这样的:

$numRow= mysql_num_rows($followup_details)

并在你的循环中:

 <td>
<?php if($slno >= $numRow) { ?>
  <a href="#" class="edit-followup" data-reveal-id="editfollowup" data-animation="fade" id="<?php echo $followup['followup_id'];?>"><img src="images/edit_icon.png" alt="editicon" width="20" height="20" border="0" class="marg" /></a>
<?php } ?>
</td>

答案 1 :(得分:0)

也许您可以在生成列表后打印编辑按钮,因此它不在循环中,而是在之后直接跟随。或者您可以在循环之前检查行数。然后在循环中放置一个计数器1.当计数器等于行数时,打印按钮。

答案 2 :(得分:0)

首先,你可以在while循环

之前获得总记录数
  $total_records = mysql_num_rows($followup_details);

现在检入while循环

if($slno == $total_records -1 )
{
  ?>
    // this is final record
<a href="#" class="edit-followup" data-reveal-id="editfollowup" data-animation="fade" id="<?php echo $followup['followup_id'];?>"><img src="images/edit_icon.png" alt="editicon" width="20" height="20" border="0" class="marg" /></a>
  <?php
 }else{
   echo "&nbsp;";
 }

答案 3 :(得分:0)

只需添加$slno的检查是1.因为您在followup_id上按降序获取记录,所以最后插入的记录将位于顶部(第一个)。

<td>
  <?php
  if($slno===1):
  ?>
  <a href="#" class="edit-followup" data-reveal-id="editfollowup" data-animation="fade" id="<?php echo $followup['followup_id'];?>"><img src="images/edit_icon.png" alt="editicon" width="20" height="20" border="0" class="marg" /></a>
  <?php
  endif;
  ?>
</td>