I am trying to work out a problem I am having with a photo selection script. How it works is the user is presented with a page of thumbnails, each thumbnail has a check box under it. If the user wants to order that photo they click the checkbox. The problem I am having is im not sure how to echo the photos out, as each of the photos is given a random name when uploaded.
For example on the page I clicked 4 photos and then hit submit, I then echo'd out all of the post data which gives me :
Array ( [984321568417_jpeg] => on [380737457699_jpeg] => on [632283404882_jpeg] => on [859974304006_jpeg] => on [albumname] => Ben & Katie [submit] => Submit )
so......if I want to put the album name into the database that's easy enough I just use
$_POST['albumname']
but I have no idea how to collect the image names from the checkboxes as the id of the posted data depends on the name of the image ?.
echo '<h1>'.$albumname.'</h1>';
echo '<p style="clear:both; float:none;">(Click an image to enlarge, select the tick box under an image to add it to the album)</p>';
$sql2 = <<<SQL
SELECT *
FROM `albums`
WHERE albumid = '$albumid' AND isalbum = ''
SQL;
if(!$result2 = $db->query($sql2)){
die('There was an error running the query [' . $db->error . ']');
}
while($row2 = $result2->fetch_assoc()){
echo '<div class="imagewrapper">';
echo '<a title="'.$row2['id'].'" class="fancybox-thumb" rel="fancybox-thumb" href="albums/'.$albumid.'/800x600/'.$row2['image'].'"><img style="border-radius:5px;" src="albums/'.$albumid.'/thumbnails/'.$row2['image'].'" /></a>';
echo '<div style="text-align:center;">';
echo '<strong>Select : </strong><input class="selectcheckbox" type="checkbox" name="'.$row2['image'].'" id="check_'.$row2['id'].'" />';
echo '</div>';
echo '</div>';
}
?>
<script>
EDIT>>>>>>>>>>>
Ok I have now added 'check_' to the start of each of the checkbox titles so I now get the following post data , so im not sure if I can put something like (put all posted data containing 'checked_' into an array on its own ?).
Array ( [check_380737457699_jpeg] => on [check_632283404882_jpeg] => on [albumname] => Ben & Katie [submit] => Submit )
Change your checkboxes to:
<input type="checkbox" name="photos[]" value="380737457699_jpeg">
Then you can var_dump($_POST['photos'])
to output something similar to:
array(
[0] => 380737457699_jpeg
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.