|
Posted by Hilarion on 07/25/05 13:49
>> This will work OK only if "nom" values are unique. If they are not, then you'll
>> always get other "duplicate" of current record as previous and as next.
>> In that case you should use something like:
>
> Many thanks four your quick answer.
>
> Yes you are right, they can have duplicate records. In fact I like to now the
> next ID and previous ID than I can make a skip and skip -1 button at the bottom
> of the windows.
>
> Someting like:
> +---------------------+
> ¦ Nom : xxxxx ¦
> ¦ Prénom : xxxxx ¦
> ¦ ... ¦
> ¦ ¦
> ¦ ¦
> +---------------------+
> < > NEW SAVE DEL <-- Buttons
>
> Until yet I did it like that (button to display the next record):
> <a href="adresse_edit.php?id=<?= $id+1 ?>">
> <img border="0" src="images/co_avant.png" width="32" height="24"></a>
>
> But this solution do not skip to the next record alphabetikally!..
It would also not work OK after deleting some records, because you
would have gaps in ID order and "$id + 1" could hit such gap.
In my opinion the better way to do "next" and "previous" is
to pass current ID and action information ("previous" or "next" or
some abbreviation of those). Why? Because if you calculate previous
and next ID on the current record page and two users work in the
same time then one of them could delete record which was calculated
as next or previous for the current record of other user and this
way the link would not work.
The best way is to check if there is any previous and next and
use link which passes current ID and action. This doubles the
amount of data retrieved from SQL database, but gives least error
situations (only one is when I display record and see "next" or
"previous" link because there are next/previous records and some
other user deletes all next or previous records, then when I click
the link, there's no record to display).
Hilarion
[Back to original message]
|