Jump to content

Recommended Posts

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.

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++;
}

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.