I want to move images up or down and its listed according to the position in database and i want to change that position in database, and it can refresh the page so the updated position can be displayed.
database structure:
image_id (pk)
property_id (fk)
description
position
status (front image of that property)
could anyone help me out its urgent.
heres the code
(these functions are in function file)
function image_positionup($image_id, $property_id, $position)
{
$sql = “select * from property_images where property_id=$property_id and position=$position and image_id=$image_id”;
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
$rowz = mysql_fetch_array($result);
$posi = $rowz[‘position’];
if($posi>1)
{
$posi=$posi - 1;
$sqlu = “update property_images set position=’$posi’ where image_id=’$image_id’ and property_id=’$property_id’”;
mysql_query($sqlu);
$sql = “select * from property_images where property_id=$property_id and position=$posi and image_id<>$image_id”;
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
$rowz = mysql_fetch_array($result);
$posi = $rowz[‘position’];
$id = $rowz[‘image_id’];
if($posi<mysql_num_rows($result))
{
$posi=$posi + 1;
$sqlu = “update property_images set position=’$posi’ where image_id=’$id’ and property_id=’$property_id’”;
mysql_query($sqlu);
$re = 5;
}
//$msg = “The Picture has been moved upwards”;
return $re;
}
}
else
{
//$msg = “The picture cannot be moved up then this”;
return 0;
}
}
}
function image_positiondown($image_id, $property_id, $position, $total)
{
$sqldo = “select * from property_images where property_id=$property_id and position=$position and image_id=$image_id”;
$resultdo = mysql_query($sqldo);
if(mysql_num_rows($resultdo) > 0)
{
$rowz = mysql_fetch_array($resultdo);
$posi = $rowz[‘position’];
if($posi<$total)
{
$posi=$posi + 1;
$sqld = “update property_images set position=’$posi’ where image_id=’$image_id’ and property_id=’$property_id’”;
mysql_query($sqld);
$sql = “select * from property_images where property_id=$property_id and position=$posi and image_id<>$image_id”;
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
$rowz = mysql_fetch_array($result);
$posi = $rowz[‘position’];
$id = $rowz[‘image_id’];
if($posi>1)
{
$posi=$posi - 1;
$sqlu = “update property_images set position=’$posi’ where image_id=’$id’ and property_id=’$property_id’”;
mysql_query($sqlu);
$re = 5;
}
//$msg = “The Picture has been moved downwards”;
return $re;
}
}
else
{
//$msg = “The picture cannot be moved down then this”;
return 0;
}
}
}
this is in the main file
<?php if($row['position']>1) { ?> <img src="images/up.png" width="30px" height="30px" onclick="<?php $retu = image_positionup($image_id, $property_id, $row['position']); ?>" />
<?php
/*if($retu==5)
{
echo "<meta http-equiv='refresh' CONTENT='0;URL=property_images.php?property_id=".md5($property_id)."'>";
*/echo "<br />";
//}
}
echo "<br />";
if($row['position']<$totalrows)
{
?>
<img src="images/down.png" width="30px" height="30px" onclick="<?php $retd = image_positiondown($image_id, $property_id, $row['position'], $totalrows); ?>" />
<?php
/*if($retd==5)
{
echo "<meta http-equiv='refresh' CONTENT='0;URL=property_images.php?property_id=".md5($property_id)."'>";
}*/
}
echo "</td></tr>";
}
?>