This is what I want to achieve:
I have a normal select query that lists records with their group_ids... like so...
group_id --- number
333
333
333
333
345
345
345
345
The number field at the moment is null, and I would like to update that field in each of these records, starting with 1, then 2 and so on... And as soon as group_id changes, from 333 to 345, I would the numbering to restart.
At the moment I have this:
Code: Select all
<?php
$x=1;
do {
?>
<tr>
<td><?php echo $row_rsOptionGroups['id']; ?></td>
<td><?php echo $row_rsOptionGroups['group_id']; ?></td>
<td><?php echo $row_rsOptionGroups['display_value']; ?></td>
<td><?
$g_id=$row_rsOptionGroups['group_id'];
$y=$g_id;
if ($y != $row_rsOptionGroups['group_id']) {
$x=1;
$g_id=$row_rsOptionGroups['group_id'];
}
echo $x;
$x=$x+1;
?></td>
<td><?php echo $row_rsOptionGroups['option_price']; ?></td>
</tr>
<?php
} while ($row_rsOptionGroups = mysql_fetch_assoc($rsOptionGroups));
?>
Is there a way I can do:
Code: Select all
If ($row_rsOptionGroups['group_id'] changes from what it previously was) {
$x=1;
}