Page 1 of 1

Problem in Moving row up or down of table unsing arrow image

Posted: Mon Apr 07, 2008 6:01 am
by ocute30
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>";
}
?>

Re: Problem in Moving row up or down of table unsing arrow image

Posted: Mon Apr 07, 2008 11:36 am
by Christopher
You didn't put your source in a code block so it if difficult to read. And you did not give a specific problem in the code. But you want urgent help?

Re: Problem in Moving row up or down of table unsing arrow image

Posted: Mon Apr 07, 2008 11:50 pm
by ocute30
i m displaying a list of images of a particular property in a table i want to change its position as user want to and its being sorted according to position no in the database i the problem tht i m having is tht when change the position of a image in the table it changes its value in database also after that when i check in the database signle position has been saved on 2 images which is giving me a problem.