|
Posted by Hendri Kurniawan on 01/03/07 21:30
Another way to do it VIA array
<?php
$vals = array();
while ($temp = fetch_row_from_db()) $vals[$temp[0]] = $temp;
var_dump($vals);
?>
This way, you are sure to get the last row of every value.
Hendri Kurniawan
Toby Inkster wrote:
> craig.keightley wrote:
>
>> value 1
>> value 1
>> value 1
>> SHOW ROW
>> value 2
>> value 2
>> SHOW ROW
>> value 3
>> value 3
>> SHOW ROW
>> value 4
>> value 4
>> SHOW ROW
>
> Thinking laterally, is "SELECT DISTINCT" an option?
>
> If not, the basic technique is this:
>
> <?php
> $oldvals = array();
>
> while ($newvals = fetch_row_from_db())
> {
> if ($newvals is different from $oldvals)
> {
> print $oldvals;
> }
> $oldvals = $newvals;
> }
>
> print $oldvals;
> ?>
>
> You will need to adapt that to your situation.
>
> This way, rather than trying to "look ahead" to the next row in the data
> set, you're actually "printing behind" the previous row. Same effect, but
> much easier to implement, because the next row is always a mystery,
> whereas the previous row is already known.
>
Navigation:
[Reply to this message]
|