简体   繁体   English

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

[英]How to display Edit Button only for last insertion Row id in php/mysql table

I have a View Grid in Php. 我在PHP中有一个View Grid。 In this Edit button(like actions edit,delete icons) need to display only for last insertion row. 在此“编辑”按钮(如动作编辑,删除图标)中,仅需要显示最后一个插入行。 Could you help me how to display like that.Here my code 您能帮我怎样显示吗?

<?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 }
  ?>

My Edit Icon only have to display last insertion Row. 我的编辑图标只需要显示最后一个插入行。 Please help me. 请帮我。 Thanks in advance 提前致谢

maybe something like this: 也许是这样的:

$numRow= mysql_num_rows($followup_details)

and in your loop: 并在您的循环中:

 <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>

Maybe You can print the edit buttons after you have generated the list, so it is not in the loop, but follows directly afterwards. 也许您可以在生成列表之后打印编辑按钮,因此它不在循环中,而是紧随其后。 Or you can check the number of rows before the loop. 或者,您可以检查循环之前的行数。 Then in the loop you put a counter from 1. When the counter is equal to the number of rows, you print the buttons. 然后在循环中放置一个从1开始的计数器。当计数器等于行数时,将打印按钮。

First, you can get total no of records before while loop 首先,您可以在while循环之前获取记录总数

  $total_records = mysql_num_rows($followup_details);

Now check in while loop 现在检查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;";
 }

Just add a check for $slno is 1. Because you are fetching records on descending order on followup_id so last inserted record will be on top (the first one). 只需添加一个$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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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