If the user is logged into the account I've got it so he can click on an image which brings it up in a popup div. inside there he can change the name of the image, change the order position and delete the image. with the deleting and re-ordering i needed to use a "while" for updating the database.
first off is i send the image ID number to the popup div. once its received the div is populated with the image thumbnail, its name and its current position. When change or delete is clicked this code is run
Code: Select all
$CurPos =$_POST['current'];
$NewPos =$_POST['new'];
$ImgID=$_POST['ID'];
//for delete
$queryA = "SELECT * FROM Test WHERE Position > $CurPos ORDER BY Position ";
$queryResourceA = mysql_query($queryA, $dbConn);
if(isset($_POST['delete'])){
$sqldelete = "Delete from Test Where testID = $ImgID";
mysql_query($sqldelete,$dbConn);
while ($row = mysql_fetch_array($queryResourceA , MYSQL_ASSOC)) {
$ToChng = $row['Position'];
$sqlposA="UPDATE Test
SET Position='$CurPos'
WHERE Position = '$ToChng '
";
mysql_query($sqlposA,$dbConn);
$CurPos++;
}} //closes the while and isset
//for update
if(isset($_POST['change'])){
if ($CurPos > $NewPos){
$Max = $CurPos;$Max--;
$queryB = "SELECT * FROM Test WHERE Position Between $NewPos AND $Max ORDER BY Position DESC ";
$queryResourceB = mysql_query($queryB, $dbConn);
else {
$Min = $CurPos;$Min++;
$queryB = "SELECT * FROM Test WHERE Position Between $Min AND $NewPos ORDER BY Position ";
$queryResourceB = mysql_query($queryB, $dbConn);
$sqlposB="UPDATE Test
SET Position='x'
WHERE Position = '$CurPos '
";
mysql_query($sqlposB,$dbConn);
while ($rowB = mysql_fetch_array($queryResourceB, MYSQL_ASSOC)) {
$tomove = $rowB['Position'];
$moveto = $tomove;
if ($CurPos > $NewPos){$moveto++;}
else {$moveto--;}
$sqlposA="UPDATE Test
SET Position='$moveto'
WHERE Position = '$tomove '
";
mysql_query($sqlposA,$dbConn);
}
$sqlposB="UPDATE Test
SET Position='$NewPos'
WHERE Position = 'x '
";
mysql_query($sqlposB,$dbConn);
}