PHP/MySQL Image array title change

UnrernUphomma

New Member
If I've got some php code, below:\[code\]while($galleryResult=mysql_fetch_array($galleryQuery)) { echo '<li><img src="http://stackoverflow.com/images/properties/gallery/'.$galleryResult['imagename'].'" width="120" height="120" class="image" /><br /> <input type="text" style="width:120px;" name="newGalleryTitle" value="'.$galleryResult['galleryTitle'].'"><br /> <label for="updateTitle'.$galleryResult['id'].'"><input id="updateTitle'.$galleryResult['id'].'" type="checkbox" name="title_ids[]" value="'.$galleryResult['id'].'" /> Update title?</label><br /> </li> '. PHP_EOL; }\[/code\]Which outputs this html, below;\[code\]<li><img src="http://stackoverflow.com/images/properties/gallery/image-name.jpg" width="120" height="120" class="image" /><br /> <input type="text" style="width:120px;" name="newGalleryTitle" value="http://stackoverflow.com/questions/3857168/Test No2"><br /><label for="updateTitle1"><input id="updateTitle1" type="checkbox" name="title_ids[]" value="http://stackoverflow.com/questions/3857168/1" /> Update title?</label><br /></li> <li><img src="http://stackoverflow.com/images/properties/gallery/image-name-02-jpg.jpg" width="120" height="120" class="image" /><br /> <input type="text" style="width:120px;" name="newGalleryTitle" value="http://stackoverflow.com/questions/3857168/Test No2"><br /><label for="updateTitle2"><input id="updateTitle2" type="checkbox" name="title_ids[]" value="http://stackoverflow.com/questions/3857168/2" /> Update title?</label><br /></li> \[/code\]etc etc. And this is the code I'm using to try and update the image 'titles', below:\[code\]if (!empty($_POST['title_ids'])) { foreach ($_POST['title_ids'] as $titleId) { $error=$_POST['newGalleryTitle']; $gtsql=mysql_query("UPDATE isgallery SET galleryTitle = '".$_POST['newGalleryTitle']."' WHERE id = ".mysql_real_escape_string($titleId)); mysql_query($gtsql); } } \[/code\]Now, this all works great if I select the last image in the array, but if I choose any other or multiple images, it will take the image title from the last image and write it into the selected image title. My question is: How do I go about 'grabbing' the correct image title? I know it's selecting the correct item/image in the array, just not the image title.Hope this makes sense and any help would be greatly appreciated. Thanks in advance, S
 
Back
Top