Re: Seeking strategy/algorithm for maintaining order of records
| From: | Tedd Sperling | Date: | Sun, 16 Oct 2011 19:52:33 +0000 |
| Subject: | Re: Seeking strategy/algorithm for maintaining order of records | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-315325@lists.php.net to get a copy of this message | ||
On Oct 15, 2011, at 8:57 PM, Stephen wrote:
> I am building a site for my photography.
>
> The photographs are displayed by category.
>
> The category table has a field for "order"
>
> In my control panel I want to be able to change the order of the categories by changing the
> values in the category field.
>
> I can dynamically build a form of all categories and have a field for new order number, Then
> loop through the POST and update the values.
>
> The field is not unique, so I am not worried about DB errors.
>
> But I wonder if there is a better way.
>
> Thoughts please?
>
> Thank you
> Stephen
>
Stephen:
What you describe is a multistep problem. There are many ways to show pictures (images) in any order
you want.
I commonly store images in a database with their associated data, such as id, image name, size,
type, category, and other such data.
Then when I want to display any image(s), I simply pull the images from the database in the order
and/or category as I want them displayed. If I want to sort them in some fashion, I can use any
field by using a MySQL query string, such as "SELECT * FROM image_db WHERE what=whatfield ASC
ORDER BY whatever".
From there it's a simple process to display the data obtained from the database by using a
pagination scheme of some type, like this:
http://php1.net/b/pagination-images/
or this:
http://webbytedd.com/bbb/paging/
In some instances, I even have a content management system where I can set the order of the pictures
I want to appear in what order by assigning them a sort order number/category.
For example, if I have 20 pictures (numbers 1-20) each having a sort number, they will be shown in
that order. If I want to change the order of the presentation, such as insert image 16 into position
3, I simply change the order number of picture 16 to 2.5 and resort the categories on integer.
Bingo, the images are resorted as I want.
There are many ways to do this -- you just need to define what you specifically want to do and break
it down into manageable parts.
Cheers,
tedd
_____________________
tedd@sperling.com
http://sperling.com