peddel Posted February 18, 2009 Share Posted February 18, 2009 My PHP is working perfectly when using this way to get the last row of a MySQL result array in PHP while($row = mysql_fetch_array($result)){ $rowLast = $row; } Then i just use $rowLast['name'] to get the name column of the row. So far everything works. What i need now is to be able to store the last row and the pre - last row. I wanted to do this by using this code $rowAmount = mysql_num_rows($result); $rowPreLast = $result[$rowAmount - 2]; $rowLast = $result[$rowAmount - 1]; But this doesnt seem to work ! Can anyone help me out? Link to comment https://forums.phpfreaks.com/topic/145733-getting-items-out-of-a-query-result-array-need-help/ Share on other sites More sharing options...
Cal Posted February 18, 2009 Share Posted February 18, 2009 $rowPreLast = $result[$rowAmount]-2; $rowLast = $result[$rowAmount]-1; I think this is what you mean Link to comment https://forums.phpfreaks.com/topic/145733-getting-items-out-of-a-query-result-array-need-help/#findComment-765139 Share on other sites More sharing options...
peddel Posted February 18, 2009 Author Share Posted February 18, 2009 $rowPreLast = $result[$rowAmount]-2; $rowLast = $result[$rowAmount]-1; I think this is what you mean Thats not what i mean, since i wanna get the element at position "rowAmount - 1" (since arrays start to count from 0 the exact last position is achieved this way) "rowAmount - 2" (pre last element) I do NOT want to subtract a value of the array value ! But thx for the try Link to comment https://forums.phpfreaks.com/topic/145733-getting-items-out-of-a-query-result-array-need-help/#findComment-765140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.