doublea2k7 Posted September 4, 2010 Share Posted September 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/ Share on other sites More sharing options...
sasa Posted September 4, 2010 Share Posted September 4, 2010 try $row = mysql_fetch_array($result); while($row1 = mysql_fetch_array($result)){ echo data from $row $row = $row1; end while $row = $row1; echo data from $row (last row) Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107261 Share on other sites More sharing options...
doublea2k7 Posted September 4, 2010 Author Share Posted September 4, 2010 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107273 Share on other sites More sharing options...
sasa Posted September 4, 2010 Share Posted September 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107276 Share on other sites More sharing options...
PaulRyan Posted September 4, 2010 Share Posted September 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107282 Share on other sites More sharing options...
doublea2k7 Posted September 4, 2010 Author Share Posted September 4, 2010 thanks for the reply PaulRyan. I've tried your code but all the rows have the same class even the last one. Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107284 Share on other sites More sharing options...
PaulRyan Posted September 4, 2010 Share Posted September 4, 2010 Ohh right, if you could post the code you used originally and the query you used also I could take another stab at it? Thanks, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107287 Share on other sites More sharing options...
Pikachu2000 Posted September 4, 2010 Share Posted September 4, 2010 There's a typo or two in the code PaulRyan posted. $countCheck = '0'; // The single quotes aren't needed. // AND // if($count == $checkCount) { $class='statusLast'; } else { $class='status'; } // ******** CHANGE $checkCount to $countCheck Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107291 Share on other sites More sharing options...
PaulRyan Posted September 4, 2010 Share Posted September 4, 2010 Well spotted Pikachu2000, fixing those should sort the problem. Paul. Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107292 Share on other sites More sharing options...
doublea2k7 Posted September 4, 2010 Author Share Posted September 4, 2010 that fix it. ty both of u =) Quote Link to comment https://forums.phpfreaks.com/topic/212534-php-mysql-fetch-last-result/#findComment-1107293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.