php-general Digest 17 Oct 2011 13:55:20 -0000 Issue 7524

Topics (messages 315328 through 315331):

Re: Seeking strategy/algorithm for maintaining order of records
        315328 by: Ashley Sheridan
        315330 by: Arno Kuhl

Re: Image Rotation Script
        315329 by: Curtis Maurand

PHP Version: 5.2.5.
        315331 by: Joseph Adenuga

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Sun, 2011-10-16 at 17:32 -0400, Stephen wrote:

> On 11-10-16 04:10 PM, Jim Giner wrote:
> > Stephen:
> >
> > What you describe is a multistep problem. There are many ways to show
> > pictures (images) in any order you want.
> > *****
> >
> > So far, the OP has only asked how to keep his "categories" in order.
> > Curious, yes, but he hasn't even asked how to display the images in order -
> > maybe he doesn't care about that..
> Well, I want to deal with one part of the design at a time :)
> 
> Thanks to all who replied. This is a collective response.
> 
> Displaying in an order is easy when you have a field called "order".
> 
> SELECT descriptions FROM categories ORDER by order;
> 
> My issue is, say I have three records:
> 
> ID Category    Order
> 
> 1    B&W            1
> 2    Landscapes 2
> 3    Nudes          3
> 
> I am looking for the best way to be able to change the values to
> 
> ID Category    Order
> 
> 1    B&W            3
> 2    Landscapes 2
> 3    Nudes          1
> 
> Dynamically building a form, entering the new order value, and then 
> looping through the post, with a SQL UPDATE is the best I can come up with.
> 
> 
> A future issue will be doing the same to the table category-photograph
> 
> ID Category_id photo_id order
> 
> This table is needed to allow a photograph to be in more than one category.
> 
> Cheers
> Stephen
> 


It depends on how you're presenting the ordering to the end user. I've
used different methods depending on the requirements of the CMS.

a) You swap over the order of two items in a list (which could be
applicable in your example but the dataset is too small to say)
b) You move an item up or down within the list, then you use some
queries (take care because multiple queries won't guarantee freedom of
DB collisions) to increment or decrement the order of all the items to
either side of the item you move up or down, then finally you
increment/decrement that individual item.
c) Lastly you could allow for a free-form entry for the order field, and
allow for multiple items to share the same order. A cleanup routine
could then arrange them properly during quiet periods for example if
you're worried about order field collision.

With any of these methods I'd swing for using transactions if you can,
because you're going to be performing multiple queries and the system
may be used by other people at the same time.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
From: Stephen [mailto:[email protected]] 
Sent: 16 October 2011 11:33 PM
To: [email protected]
Subject: Re: [PHP] Seeking strategy/algorithm for maintaining order of
records

Displaying in an order is easy when you have a field called "order".

SELECT descriptions FROM categories ORDER by order;

My issue is, say I have three records:

ID Category    Order

1    B&W            1
2    Landscapes 2
3    Nudes          3

I am looking for the best way to be able to change the values to

ID Category    Order

1    B&W            3
2    Landscapes 2
3    Nudes          1

Dynamically building a form, entering the new order value, and then looping
through the post, with a SQL UPDATE is the best I can come up with.

A future issue will be doing the same to the table category-photograph

ID Category_id photo_id order

This table is needed to allow a photograph to be in more than one category.

Cheers
Stephen

-- 

One way would be to use ajax. Each time a photo is moved up or down the
order list you issue an ajax request to update the order. That way your php
script only needs to deal with 2 records at a time and switch their order
values.

Besides that, I can't think of any way of processing a form with multiple
order changes other than looping through the post the way you described.

Cheers
Arno


--- End Message ---
--- Begin Message ---

There are tons of (free) jquery gadgets that do image rotation. All you'd need to do is push the list out to the jquery script.

Cheers,
Curtis

On 10/15/2011 10:50 AM, [email protected] wrote:
We have a simple script which rotates and image to a random value, saves
it to a cache directory and displays it. For some reason when I move the
script from a Debian box over to the production CentOS machine, it no
longer caches any of the images. the rest works, but not the cache. If you
could look at it and see if anything jumps out at you, please let me know.

install the code below to the directory /angles


.htaccess:
RewriteEngine on
RewriteRule ^rotate_(\d+)(?:_(?:\d+))?.png$ rotate.php?im=$1

rotate.php:
<?php
// Setup
if(isset($_GET['im'])&&  file_exists($_GET['im'].'.png')) {
header('Content-type: image/png');
$im = $_GET['im'].'.png';
$degrees = rand(0, 360);
$save = 'cache/'.$_GET['im'].'_'.$degrees.'.png';
if(!file_exists($save)) {
// Rotate via "command line" and cache it
exec('convert '.$im.' -filter \'Lanczos\' -resize \'150x150\' -rotate
'.$degrees.' -black-threshold 40% '.$save, $out);
}
// Output out (newly?) cached file
echo file_get_contents($save);
} else {
die("Image not found");
}
?>

Use it by url:
http://www.servername.com/angles/rotate_019.png
Each time you reload page the angle should rotate to a new position.




--- End Message ---
--- Begin Message ---

Operating System: Window XP

PHP Version: 5.2.5. with Apache 2.2.8

My Firefox browser returns (Output) the same php script code I inserted in 
Notepad:  <?php 

    echo "<h1>Hello
Web!</h1>"; 

?>

 

Please, what am I doing wrong?


--- End Message ---

Reply via email to