andreigoea Posted November 10, 2009 Share Posted November 10, 2009 Hello, Please be kind, this is my first ever PHP script and I've only worked on it 2 days. The script should first display images. The information for the images is located in an xml file.They are sorted by the ID tags in the xml. After displaying the images I want the user to be able to change their order by changing the ID tag in the xml. I've done pretty much everything but it just doesn't swap the id's correctly. <?php // LOAD XML //---------------------------------------------------------------- //Count Clip $xmlDoc = new DOMDocument(); $xmlDoc->load("content.xml"); $clip = $xmlDoc->getElementsByTagName("clip"); $clipUrl = $xmlDoc->getElementsByTagName("file"); $elNo = $clip->length; $rowsNo = $elNo/8; $rowsNo = ceil($rowsNo); $contentHeight = $rowsNo*160+10; //Get Clip Name $imgTitles = $xmlDoc->getElementsByTagName("title"); //Get Clip No $no = $xmlDoc->getElementsByTagName("no"); //MOVE SCRIPT //---------------------------------------------------- // if(isset($_POST['add'])) { $noPressed = $_POST["imageNo"]; $noPressedb = $_POST["imageNob"]; $noPresseda = $_POST["imageNoa"]; $currentNo=($no->item($noPressed)); $newCurrentNo= $xmlDoc->createElement('no', $noPresseda); $currentNo->parentNode->replaceChild($newCurrentNo, $currentNo); $nextNo=($no->item($noPresseda)); $newNextNo= $xmlDoc->createElement('no', $noPressed); $nextNo->parentNode->replaceChild($newNextNo,$nextNo); $xmlDoc->save('content.xml'); } else if(isset($_POST['sub'])) { $noPressed = $_POST["imageNo"]; $noPressedb = $_POST["imageNob"]; $noPresseda = $_POST["imageNoa"]; $currentNo=($no->item($noPressed)); $newCurrentNo= $xmlDoc->createElement('no', $noPressedb); $currentNo->parentNode->replaceChild($newCurrentNo, $currentNo); $nextNo=($no->item($noPressedb)); $newNextNo= $xmlDoc->createElement('no', $noPressed); $nextNo->parentNode->replaceChild($newNextNo,$nextNo); $xmlDoc->save('content.xml'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <?php echo "<div id='pics' style='margin:auto; width:960px; height:"; echo $contentHeight; echo "px; background-color:#e6e6e6; border:2px solid #a02223;'>"; for ($imgCount=0; $imgCount < $elNo; $imgCount += 1){ $noV=($no->item($imgCount)->nodeValue); $noVb=($no->item($imgCount-1)->nodeValue); $noVa=($no->item($imgCount+1)->nodeValue); $image=($clipUrl->item($noV)->nodeValue); $imgTitle=($imgTitles->item($noV)->nodeValue); $subNo = "<div><form id='$imgCount moveDown' action='$_SERVER[php_SELF]' name='$imgCount moveDown' enctype='multipart/form-data' action='' method='post'> <input name='imageNo' type='hidden' value='$noV' /> <input name='imageNob' type='hidden' value='$noVb'/> <input name='imageNoa' type='hidden' value='$noVa'/> <input type='submit' name='sub' value='<' > </form></div>"; $addNo = "<div><form id='$imgCount moveUp' action='$_SERVER[php_SELF]' name='$imgCount moveUp' enctype='multipart/form-data' action='' method='post'> <input name='imageNo' type='hidden' value='$noV' /> <input name='imageNob' type='hidden' value='$noVb'/> <input name='imageNoa' type='hidden' value='$noVa'/> <input type='submit' name='add' value='>' > </form></div>"; if(file_exists($image)) { list($width, $height, $type, $attr) = getimagesize($image); if ($height>$width){ printf("<div style='padding:5px; width:110px; height:150px; float:left; margin:0px; border-bottom:1px solid #333333;'><div style='height:100px; width:100px;'><A href='$image'><img src='$image' height='100' alt='$image'></A></div><div style='padding:2px; text-align:left; width:100%%;'>$imgTitle </div> <table><tr><td>$subNo</td><td> $addNo </td></tr></table></div>"); } else { printf("<div style='padding:5px; width:110px; height:150px; float:left; margin:0px; border-bottom:1px solid #333333;'><div style='height:100px; width:100px;'><A href='$image'><img src='$image' width='100' alt='$image'></A></div><div style='padding:2px; text-align:left; width:100%%;'>$imgTitle </div> <table><tr><td>$subNo</td><td> $addNo </td></tr></table></div>"); } } else { printf("<div style='padding:5px; width:110px; height:150px; float:left; margin:0px;border-bottom:1px solid #333333;'>No Image</div>") ; } echo '<br> noV=' .$noV; echo '<br> noVb=' .$noVb; echo '<br> noVa=' .$noVa; } echo "<br></div>"; ?> </body> </html> The script is located at:http://mediapod.org/ProPlayer/order.php Let me know if you need any more info on the code. I've spent 12 hours messing with the variables and sorting criteria to no avail. Thank you. Link to comment https://forums.phpfreaks.com/topic/181035-code-that-sorts-multiple-divs-according-to-xml-node/ Share on other sites More sharing options...
andreigoea Posted November 11, 2009 Author Share Posted November 11, 2009 Should I add more info, or is the method I'm trying to use completely wrong? Link to comment https://forums.phpfreaks.com/topic/181035-code-that-sorts-multiple-divs-according-to-xml-node/#findComment-955784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.