Hi,
am write a code for editing the image and thumbnails which are store in xml file.
when the user want to change the location of array he simply select give the order
image and image name.If we select the order 1 for the image 3.jpg which having 3 rd position in array it should be come to the first position & first element goes to second please.
I write the following code for that but it is not changing positions. Please could you help for how to change the position of array!
if(isset($_POST['submit']))
{
$position= $POST['t1'] ;
$file= $POST['t2'];
echo "position is".$position ."<br>";
echo "file is". $file ."<br>";
echo "file is".$person_data[$position]['img']."<br>" ;
$article = $file;
echo "article is".$article;
$thisPos = -1;
$elementPos = 0;
$filename = 'gallery.xml';
if (!$fp = fopen($filename, 'w+')) {
print "Cannot open file ($filename)";
exit;
}
$lengthOfArray = count($person_data);
echo "length is". $lengthOfArray."<br>";
/adding /
for( $i=0 ; $i < $lengthOfArray ; ++$i )
{
$thisName = $person_data[$i]["thumb"];
//echo "this name is".$thisName . "<br>";
if ($thisName == $article) {
echo "<b> match at position number: ". $i . "</b><br>";
$thisPos = $i;
echo "our match happened at". $thisPos."<br>";
if ($thisPos==-1)
{
echo "$i;br>its NOT on the ARRAY thisPos value is $thisPos we need to append";
$elementPos = $lengthOfArray;
}
else
{
//echo "$i;br>it IS on the ARRAY at postion $thisPos we need to over write";
$elementPos = $thisPos;
echo "elementpos".$elementPos."<br>";
}
//echo "$i;br>---this is elementpos value $elementPos<br>";
echo "before if. <br>";
if ($person_data == ''|| $elementPos == ''|| $position == '' || $position > count($person_data) || $position < 1 || $elementPos > count
($person_data) || $elementPos < 1 )
{
echo "error";
}
else
{
echo "success.<br>";
$hopper = $person_data[$elementPos];
echo "array count is".count($hopper)."<br>";
echo " hopperthumb is".$hopper['thumb']."<br>";
echo " hopperthumb is".$hopper['img']."<br>";
$hopperval=array();
$hopperval[0]['thumb']=$hopper['thumb'];
$hopperval[0]['img']=$hopper['img'];
$left = array_slice ($person_data, 0, $elementPos-1);
echo "left is<br>";
print_r($left);
$right = array_slice($person_data, $position);
echo "count of right is".count($right)."<br>";
print_r($right);
$array = array_merge ($left, $right);
echo "after merge<br>";
print_r($array);
foreach($hopper as $key=>$item )
{
echo "key is". $key."<br>";
echo "item is".$item."<br>";
$hopperval[0].=$item;
}
for($i=0; $i<count($hopper); $i++)
{
$hopperval[$i].=$hopper[$i];
}*/
echo "printing hopperval";
print_r($hopperval);
//echo "hopper is".$hopper."<br>";
echo "after function call";
//echo "afterdelete array is<br>";
//print_r($array);
// $array = $this->insert($array, $to, $hopper);
}
//$our_array = $tweak_array->move($person_data, $elementPos,$position);
//echo "after moving array is<br>";
//print_r($our_array);
/////////////////////////////
/// adding data sent over////
/////////////////////////////
}
}
$somecontent = "<?xml version=\"1.0\"?>\n";
$somecontent .= "<gallery>\n";
for( $i=0 ; $i < $person_counter ; ++$i )
{
$somecontent .= "<item>\n";
$thisName = $person_data[$i];
print_r ($thisName);
foreach($thisName As $myKey => $myContent)
{
$somecontent .= "<".$myKey . ">".$myContent . "</". $myKey .">". "\n";
}
$somecontent .= "</item>\n\n";
}
$somecontent .= "</gallery>\n";
//echo $somecontent;
if (!fwrite($fp, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}
//remembering to close the file.
fclose($fp);
}
// header("Location: gallery.php");
?>