Jump to content

[SOLVED] How to do this kind of update


play_

Recommended Posts

I have a list of images the user can re-order using javascript(sortables)

 

When the user re-arrange the images, moving their position around, it returns me the order of the images.

 

now in the database, my images table looks(in short) like this:

 

| name | size | order |

+------+-----+------+

| a.jpg |  12  |  1    |

| b.jpg |  12  |  2    |

| c.jpg |  12  |  3    |

 

 

 

After images are rearranged, it sends their order to a PHP script( i send it as ints).

I put them into an array, so it looks like this:( say ajax sends the  new order as( 2, 3 , 1)

$order[0] = 2
$order[1] = 3
$order[2] = 1.

 

What i would like to do, is now have picture

'a.jpg' `order` column be 2,

'b'.jpg' `order` column be 3

'c.jpg' `order` column be 1

in the database

 

How would i do such update?

Would i have to pass the name(or id) of the image through ajax as well, so i could(in a loop) do:

 

update images set `order` = {$order[0]} where ID = $id

 

or is there a simpler way?

Link to comment
https://forums.phpfreaks.com/topic/130767-solved-how-to-do-this-kind-of-update/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.