KvickaN Posted January 15, 2011 Share Posted January 15, 2011 Hello guys. I have a form with 20 images. My user have to write a description for each image and when submitting the form the user will get an HTML code which will display an album. My problem is that my users want to choose a sequence of the images in the album. How do I solve that? I tried with making a select with 20 options (number 1-20) for each image and a desription for the user to place them in a correct sequence but I don't know how to do it. And another problem is when a user chooses the same number for more than one image. Thanks Link to comment https://forums.phpfreaks.com/topic/224541-how-to-sort-post-data-in-a-sequence/ Share on other sites More sharing options...
phpfreak Posted January 15, 2011 Share Posted January 15, 2011 Can you give an example of the code? Link to comment https://forums.phpfreaks.com/topic/224541-how-to-sort-post-data-in-a-sequence/#findComment-1159876 Share on other sites More sharing options...
KvickaN Posted January 15, 2011 Author Share Posted January 15, 2011 Thanks. Here it is: // Show the images: $i = 0; $dir = opendir("../images"); while (($image = readdir($dir)) !== false) { if ($image != "." && $image != "..") { $i++; image_table_row($image, $i); } } // Here is the function: function image_table_row($image, $i) { echo "<tr>"; echo "<td style=\"width:150px;\"><img src=\"http://".$_SERVER['HTTP_HOST']."/images/".$image."\" style=\"width:100px;height:100px;\" /></td>"; echo "<td style=\"width:150px;\"><input type=\"text\" maxlength=\"65\" name=\"desc-".$i."\" /></td>"; echo "<td><select name=\"order-".$i."\" style=\"width:60px;\"> <option value=\"0\" selected=\"selected\">-</option>"; for ($i2 = 1; $i2 <= 20; $i2++) { echo "<option value=\"".$i2."\">".$i2."</option>"; } echo "</select></td></tr>"; echo "<input type=\"hidden\" value=\"".$image."\" name=\"img-".$i."\" />"; } // Code when submitting the form: // HOW DO I GET THE SORTING CORRECT IN HERE? if(isset($_POST['submit'])) { $html = ""; for ($i = 1; $i <= 20; $i++) { if(isset($_POST["order-".$i.""]) && $_POST["order-".$i.""] > "0") { $html .= "\n<div class=\"image-gallery\"><a href=\"http://".$_SERVER['HTTP_HOST']."/images/".$user."/".$_POST["img-".$i.""]."\" rel=\"lightbox[1]\""; if($_POST["desc-".$i.""] != "") { $_POST["desc-".$i.""] = str_replace("<?", "<?", $_POST["desc-".$i.""]); $_POST["desc-".$i.""] = str_replace("?>", "?>", $_POST["desc-".$i.""]); $html .= " title=\"".$_POST["desc-".$i.""]."\" "; } $html .= "><img src=\"http://".$_SERVER['HTTP_HOST']."/images/".$user."/mini-".$_POST["img-".$i.""]."\" /></a>"; if($_POST["desc-".$i.""] != "") { $html .= "<div>".$_POST["desc-".$i.""]."</div>"; } $html .= "</div>\n"; } } $html .= "\n<div style=\"clear:both;height:0;\"> </div>"; echo "<textarea style=\"width:500px;height:300px;\">".htmlspecialchars($html)."</textarea>"; } Link to comment https://forums.phpfreaks.com/topic/224541-how-to-sort-post-data-in-a-sequence/#findComment-1159881 Share on other sites More sharing options...
KvickaN Posted January 16, 2011 Author Share Posted January 16, 2011 Bump, any ideas? Link to comment https://forums.phpfreaks.com/topic/224541-how-to-sort-post-data-in-a-sequence/#findComment-1160080 Share on other sites More sharing options...
KvickaN Posted January 17, 2011 Author Share Posted January 17, 2011 Anyone? Link to comment https://forums.phpfreaks.com/topic/224541-how-to-sort-post-data-in-a-sequence/#findComment-1160654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.