Jump to content

Php mysql fetch last result


doublea2k7

Recommended Posts

Im not sure where to post this but since it includes php il post it here instead of in the mysql forum.

 

ok so, i have a table and i get the values using

while($row = mysql_fetch_array($result)){

and then echo them in rows.

 

that works fine but i need to add a class to the last row of my table. I would need somehow to fetch the last row of the array and make it echo something different.

 

Any help is appreciated

 

Thank you

Link to comment
Share on other sites

thers a syntax error here is a snipet of my code. Its something wrong with the endwhilte but i dont know wat is it.

 

      <?php
$row2 = mysql_fetch_array($result);	  
while($row = mysql_fetch_array($result)){ ?>
<tr id="<?php echo $row['statusid']?>" class="status">
<td><?php echo $row['date']?></td>
<td id="<?php echo$row['statusid']?>" style="text-align:left;" class="editStatus">
<?php echo htmlspecialchars($row['statusTxt'], ENT_QUOTES)?></td>
<td style="width:1%;">
<form action="">
<input type="image" src="img/cancel.png"  onclick="makeVariable('<?php echo $row['statusid']?>')" class="deleteRowButton"/>
</form>
</td>
</tr>
<?php $row2 = $row;?>
<?php
}
end while?>
<tr id="<?php echo $row['statusid']?>" class="statusLast">
<td><?php echo $row['date']?></td>
<td id="<?php echo$row['statusid']?>" style="text-align:left;" class="editStatus">
<?php echo htmlspecialchars($row['statusTxt'], ENT_QUOTES)?></td>
<td style="width:1%;">
<form action="">
<input type="image" src="img/cancel.png"  onclick="makeVariable('<?php echo $row['statusid']?>')" class="deleteRowButton"/>
</form>
</td>
</tr>

<?php } ?>

Link to comment
Share on other sites

remove end while 
it's just remnark in pseudo code[code=php:0]<?php
$row = mysql_fetch_array($result);	  
while($row2 = mysql_fetch_array($result)){ ?>
<tr id="<?php echo $row['statusid']?>" class="status">
<td><?php echo $row['date']?></td>
<td id="<?php echo$row['statusid']?>" style="text-align:left;" class="editStatus">
<?php echo htmlspecialchars($row['statusTxt'], ENT_QUOTES)?></td>
<td style="width:1%;">
<form action="">
<input type="image" src="img/cancel.png"  onclick="makeVariable('<?php echo $row['statusid']?>')" class="deleteRowButton"/>
</form>
</td>
</tr>
<?php $row = $row2;?>
<?php
}
$row=$row2;
?>
<tr id="<?php echo $row['statusid']?>" class="statusLast">
<td><?php echo $row['date']?></td>
<td id="<?php echo$row['statusid']?>" style="text-align:left;" class="editStatus">
<?php echo htmlspecialchars($row['statusTxt'], ENT_QUOTES)?></td>
<td style="width:1%;">
<form action="">
<input type="image" src="img/cancel.png"  onclick="makeVariable('<?php echo $row['statusid']?>')" class="deleteRowButton"/>
</form>
</td>
</tr>

<?php } ?>

but i don't see any diferents for last row

Link to comment
Share on other sites

Hello Doublea2k7.

 

Try the following

<?php
  $row = mysql_fetch_array($result);  
  $count = mysql_num_rows($result);
  $countCheck = '0';
  while($row2 = mysql_fetch_array($result)){ $countCheck++;

  if($count == $checkCount) { $class='statusLast'; } else { $class='status'; }
?>

<tr id="<?php echo $row['statusid']?>" class="<?PHP echo $class;?>">
  <td><?php echo $row['date']?></td>
  <td id="<?php echo$row['statusid']?>" style="text-align:left;" class="editStatus">
   <?php echo htmlspecialchars($row['statusTxt'], ENT_QUOTES)?></td>
  <td style="width:1%;">
   <form action="">
   <input type="image" src="img/cancel.png"  onclick="makeVariable('<?php echo $row['statusid']?>')" class="deleteRowButton"/>
   </form>
  </td>
</tr>

<?php } ?>

 

Instead of

      <?php
$row2 = mysql_fetch_array($result);
while($row = mysql_fetch_array($result)){ ?>
<tr id="<?php echo $row['statusid']?>" class="status">
<td><?php echo $row['date']?></td>
<td id="<?php echo$row['statusid']?>" style="text-align:left;" class="editStatus">
<?php echo htmlspecialchars($row['statusTxt'], ENT_QUOTES)?></td>
<td style="width:1%;">
<form action="">
<input type="image" src="img/cancel.png"  onclick="makeVariable('<?php echo $row['statusid']?>')" class="deleteRowButton"/>
</form>
</td>
</tr>
<?php $row2 = $row;?>
<?php
}
end while?>
<tr id="<?php echo $row['statusid']?>" class="statusLast">
<td><?php echo $row['date']?></td>
<td id="<?php echo$row['statusid']?>" style="text-align:left;" class="editStatus">
<?php echo htmlspecialchars($row['statusTxt'], ENT_QUOTES)?></td>
<td style="width:1%;">
<form action="">
<input type="image" src="img/cancel.png"  onclick="makeVariable('<?php echo $row['statusid']?>')" class="deleteRowButton"/>
</form>
</td>
</tr>

<?php } ?>

 

Tell me how it goes :)

 

Paul.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.