I have a series of 16 images. The image locations and associated text elements are stored in a MySQL database.
They normally display like this:
http://costello-media.com/stx/gallery.php with a basic Dreamweaver PHP SELECT statement.
The Client wants to be able to adjust the order of the images after I'm completed. So I'm trying to build a page that calls up all the rows and the associated order numbers in text boxes. The client would then be able to change the order number, for as many as he likes, then hit submit and all the order numbers that have been changed would updated in the database.
AT this point I have the following code in the form:
<form id="seq_form" name="seq_form" method="POST" action="<?php echo $editFormAction; ?>">
<?php do { ?>
<table width="250" border="0" cellpadding="1">
<tr>
<td><img src="images/gallery/thumbs
/<?php echo $row_pics['thumb_url']; ?>" alt="thumb" width="150" /></td>
<td><label>
<input name="order" type="text" id="order" value="<?php echo $row_pics['order']; ?>" size="3" />
<br />
<input name="id" type="hidden" id="id" value="<?php echo $row_pics['id']; ?>" />
</label></td>
</tr>
</table>
<br />
<?php } while ($row_pics = mysql_fetch_assoc($pics));
?>
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
<input type="hidden" name="MM_update" value="seq_form" />
</form>
and the following in the header:
<?php
if (!function_exists("GetSQLV
alueString
")) {
function GetSQLValueString($theValu
e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea
l_escape_s
tring") ? mysql_real_escape_string($
theValue) : mysql_escape_string($theVa
lue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STR
ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE
RY_STRING'
]);
}
if ((isset($_POST["MM_update"
])) && ($_POST["MM_update"] == "seq_form")) {
$updateSQL = sprintf("UPDATE gallery SET `order`=%s WHERE id=%s",
GetSQLValueString($_POST['
order'], "int"),
GetSQLValueString($_POST['
id'], "int"));
mysql_select_db($database_
stx_galler
y, $stx_gallery);
$Result1 = mysql_query($updateSQL, $stx_gallery) or die(mysql_error());
$updateGoTo = "gal_admin.php";
if (isset($_SERVER['QUERY_STR
ING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_
stx_galler
y, $stx_gallery);
$query_pics = "SELECT * FROM gallery ORDER BY `order` ASC";
$pics = mysql_query($query_pics, $stx_gallery) or die(mysql_error());
$row_pics = mysql_fetch_assoc($pics);
$totalRows_pics = mysql_num_rows($pics);
?>
It appears to me, based on what I've read elsewhere on EE, I need to do a while loop. My attempts at it have failed. I'm not tied to the Dreamweaver code, meaning I'm pretty comfortable with doing some "hand"coding, but I think I really need help on this.
Thanks in advance.
Start Free Trial