Page 1 of 1
Reorder random number of items in a form
Posted: Thu Jan 04, 2007 1:57 pm
by speedy33417
I'm trying to do something like what Netflix does to reorder your DVD queue. It will be used in the admin page in my photo album, where different albums contain different number of pictures.
I would display a text input box with the current value of the picture's order number and the thumb picture, loop it as many times as many picture I have and close it with a submit button.
My problem is I can do it with one variable, but I'm not sure how to loop it. I need to use either $pic1 $pic2 $pic3 $pic4 or $pic[1] $pic[2] $pic[3] $pic[4].
How do I send these variables using HTML forms and making up the full name of the variable in a loop on the fly?
Thanks.
Posted: Thu Jan 04, 2007 2:03 pm
by feyd
I'm not exactly sure what you're talking about, can you post some code, or explain in more detail?
Posted: Thu Jan 04, 2007 2:12 pm
by aliasxneo
I'm lost as well. Are you trying to use an array of values in an HTML form?
If so it's pretty simple:
Code: Select all
$pictures = array("pic1.jpg", "pic2.jpg", "pic3.jpg");
foreach ($pictures as $picture)
{
echo "<input type=\"text\" name=\"pictures[]\" />";
}
And when the form is submitted:
Code: Select all
foreach ($_POST['pictures'] as $picture)
{
echo $picture;
}
But I'm really not sure what you're talking about.
Posted: Thu Jan 04, 2007 2:18 pm
by jyhm
How about having php read through your directory and count the pictures, no?
Posted: Thu Jan 04, 2007 2:21 pm
by Kieran Huggins
Posted: Thu Jan 04, 2007 7:53 pm
by speedy33417
I thought the whole Netflix thing would help, but apperently nobody understood what I meant.
I'm using database to store my picture filename and the order they should be displayed. There's more data stored, but that's not relevant here.
For example displaying an album with album_id 1. My query would be WHEN album_id = 1 ORDER BY picture_order
Code: Select all
picture_id album_id picture_order picture_filename
123 1 1 IMG_0235.jpg
524 1 2 IMG_1347.jpg
678 1 3 IMG_2568.jpg
159 1 4 IMG_1234.jpg
Now I'm trying to do an admin page to reorder these pictures if needed. The admin page would display all four thumb pictures in the current order with an input box for each filled in with the current value of picture_order
Like so:
Code: Select all
+---+
| 1 | Thumb of IMG_0235.jpg
+---+
+---+
| 2 | Thumb of IMG_1347.jpg
+---+
+---+
| 3 | Thumb of IMG_2568.jpg
+---+
+---+
| 4 | Thumb of IMG_1234.jpg
+---+
+--------+
| UPDATE |
+--------+
So, to switch the first two pictures I would only have to update the numbers 2 1 3 4 and hit update.
Hope this explains a little better. I can display everything, but I'm having trouble sending and receiving the data as an array.
This is my code with the loop in place, but no arrays.
Code: Select all
for ($i = 1; $i < $totalPicsInAlbum; $i++)
{
echo "<td><input name=\"txtPicOrder\" value=\"" . $pictureOrder[$i]. "\" class=\"form1\"></td>";
echo "<td><image border=\"0\" src=\"blah blah\"></td>";
echo "</tr><tr>";
}
then
$pictureOrder = $_POST['txtPictureOrder'];
Posted: Thu Jan 04, 2007 9:12 pm
by Kieran Huggins
Code: Select all
for ($i = 1; $i < $totalPicsInAlbum; $i++)
{
echo "<td><input name=\"txtPicOrder[".$i."]\" value=\"" . $pictureOrder[$i]. "\" class=\"form1\"></td>";
echo "<td><image border=\"0\" src=\"blah blah\"></td>";
echo "</tr><tr>";
}
then
$pictureOrder = $_POST['txtPictureOrder'];
now you'll have the array you're looking for