loicdudu Posted January 14, 2008 Share Posted January 14, 2008 Hi, I am a beginner at PHP and i'm trying to use current() and end() functions to display a slightly different layout for the last row of the array. I have been trying to find the solution but couldn't. Here is the first part of the code: while(list($underpageid, $underpageauthor, $underpagetitle, $underpagetarget, $underpagestatus, $underpagelevel_x, $underpagelevel_xx, $underpagelevel_xxx, $underpagepath) = mysql_fetch_array($underpageresult, MYSQL_NUM)) { /* Here I would like to be able to say: If it's not the last row, echo "blabla", if it's the last row, echo "BLABLA", but it doesn't work: */ if (current($underpageresult) != end($underpageresult)) { echo "blabla"; } elseif (current($underpageresult) == end($underpageresult)) { echo "BLABLA"; } } I understand $underpageresult is not an array, it is the mysql query variable. But then, how can I define the while look with the mysql_fetch_array so that I can determine which row is the last and slightly change the html layout for this last row using an if statement ? All I get from this is that I am not "passing an array". :-\ Thank you very much for your help. Link to comment https://forums.phpfreaks.com/topic/86010-using-end-and-current-with-mysql-fetch-array/ Share on other sites More sharing options...
mrdamien Posted January 14, 2008 Share Posted January 14, 2008 current()/end() dont return the values your expecting, so try this instead: $numberOfRows = mysql_num_rows(); $rowCounter = 0; while(list($underpageid, $underpageauthor, $underpagetitle, $underpagetarget, $underpagestatus, $underpagelevel_x, $underpagelevel_xx, $underpagelevel_xxx, $underpagepath) = mysql_fetch_array($underpageresult, MYSQL_NUM)) { /* Here I would like to be able to say: If it's not the last row, echo "blabla", if it's the last row, echo "BLABLA", but it doesn't work: */ if ($rowCounter != $numberOfRows) { echo "blabla"; } elseif ($rowCounter == $numberOfRows) { echo "BLABLA"; } $rowCounter++; } Link to comment https://forums.phpfreaks.com/topic/86010-using-end-and-current-with-mysql-fetch-array/#findComment-439268 Share on other sites More sharing options...
loicdudu Posted January 15, 2008 Author Share Posted January 15, 2008 Thank you Mr Damien ! It works perfect ! Loic Link to comment https://forums.phpfreaks.com/topic/86010-using-end-and-current-with-mysql-fetch-array/#findComment-440081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.