PHP/MySQL图像数组标题更改
如果我有一些php代码,如下所示:PHP/MySQL图像数组标题更改,php,Php,如果我有一些php代码,如下所示: while($galleryResult=mysql_fetch_array($galleryQuery)) { echo '<li><img src="../../images/properties/gallery/'.$galleryResult['imagename'].'" width="120" height="120" class="ima
while($galleryResult=mysql_fetch_array($galleryQuery)) {
echo '<li><img src="../../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;
}
现在,如果我选择数组中的最后一个图像,这一切都非常有效,但是如果我选择任何其他或多个图像,它将从最后一个图像中获取图像标题并将其写入选定的图像标题中
我的问题是:我如何“抓住”正确的图像标题?我知道它是在数组中选择正确的项目/图像,而不是图像标题
希望这是有意义的,任何帮助都将不胜感激。提前感谢,S替换您的
while($galleryResult=mysql_fetch_array($galleryQuery)) {
echo '<li><img src="../../images/properties/gallery/'.$galleryResult['imagename'].'" width="120" height="120" class="image" /><br />
<input type="text" style="width:120px;" name="newGalleryTitle"
是的-从循环中删除第二个mysql_查询,因为您已经有过一次了。您需要删除这个mysql_查询($gtsql);(双重查询!)-请给我看看打印件($_POST['title\u id');我想他在那里无意中提出了第二个问题。。
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);
}
}
while($galleryResult=mysql_fetch_array($galleryQuery)) {
echo '<li><img src="../../images/properties/gallery/'.$galleryResult['imagename'].'" width="120" height="120" class="image" /><br />
<input type="text" style="width:120px;" name="newGalleryTitle"
while($galleryResult=mysql_fetch_array($galleryQuery)) {
echo '<li><img src="../../images/properties/gallery/'.$galleryResult['imagename'].'" width="120" height="120" class="image" />';
echo '<input type="text" style="width:120px;" name="newGalleryTitle['. $galleryResult['id'] .']" value="'.$galleryResult['galleryTitle'].'">';
echo '<label for="updateTitle'.$galleryResult['id'].'"><input id="updateTitle'.$galleryResult['id'].'" type="checkbox" name="title_ids[]" value="'.$galleryResult['id'].'" /> Update title?</label>';
echo '</li>'. PHP_EOL;
}
foreach ($_POST['title_ids'] as $titleId) {
$error=$_POST['newGalleryTitle'][$titleId];