Jump to content

Getting items out of a query result array [NEED HELP]


peddel

Recommended Posts

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?

$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 :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.