Page 1 of 1
array
Posted: Mon Dec 13, 2010 11:55 am
by Anant
I am using the while loop to step through array -
Code: Select all
while ($row = mysql_fetch_array($result)) { }
Now i want to put some conditions in only first row of the array in particular column. What would be the best way to do that ?
I know you can access column using
but i want to place condition in only first row.
Thanks
Re: array
Posted: Mon Dec 13, 2010 12:16 pm
by AbraCadaver
I'm not sure I understand, but something like this?
Code: Select all
while($row = mysql_fetch_array($result)) {
$rows[] = $row;
}
$rows[0]['name'] = 'something';
Re: array
Posted: Mon Dec 13, 2010 1:06 pm
by McInfo
or
Code: Select all
if ($row = mysql_fetch_array($result)) {
/* Process first row here */
while ($row = mysql_fetch_array($result)) {
/* Process additional rows here */
}
}
or
Code: Select all
$i = 0;
while ($row = mysql_fetch_array($result)) {
if ($i == 0) {
/* Do something different for first row here */
}
$i++;
}
or
Code: Select all
$isFirstRow = true;
while ($row = mysql_fetch_array($result)) {
if ($isFirstRow) {
/* Do something different for first row here */
$isFirstRow = false;
}
}