nitesh Posted February 6, 2012 Share Posted February 6, 2012 Hiiam trying to set position for my pages but i don't know how to do this php and mysql <?php if($_SERVER['REQUEST_METHOD'] =='POST') { $id = $_REQUEST['id']; $pHeading = $_POST['PageHeading']; $pName = $_POST['PageName']; $pPosition = $_POST['txtPosition'];This is the value for position $pContent = addslashes(trim($_POST['Content'])); $status = $_POST['txtStatus']; if($pHeading and $pName and $pContent) { $qryUpdate = "UPDATE pages SET PageHeading='$pHeading', PageName='$pName ', position='$pPosition',Content='$pContent',Status='$status'WHERE PageNo='$id'"; $rsUpdate = dbQuery($qryUpdate); header("Location:".DIRSERVERNAME . "php/adminPages.php"); } else { ?> <script>showAlert("The name Heading and the content is left empty.")</SCRIPT> <?php } } $id = $_GET['id']; $query = "SELECT * FROM pages WHERE PageNo = '$id'"; $rsQuery = dbQuery($query); $rsResult = dbFetchArray($rsQuery); ?> This is the php and mysql code for form i have set.<select name="txtPosition"> <option value="">Select Position</option> <?php $query1 = "SELECT position FROM pages WHERE PageNo = '$id'"; $rsQuery1 = dbQuery($query1); $rsResult1 = dbFetchRow($rsQuery1); echo "<option selected='selected' value='" .$rsResult1[0]."'> " .$rsResult1[0]. "</option>"; $query2 = "SELECT position FROM pages WHERE PageNo != '$id'"; $rsQuery2 = dbQuery($query2); while ($row2 = dbFetchRow($rsQuery2)) { echo "<option value='" .$row2[0]."'> " .$row2[0]. "</option>"; } ?> </select>Need Help Thanks in advanced Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2012 Share Posted February 6, 2012 What is that code not doing that you need to do? It looks like you're getting the value from the form and updating the database, and there's a dropdown that shows positions for all pages with the same ID. What exactly are you missing or trying to do? Link to comment Share on other sites More sharing options...
nitesh Posted February 6, 2012 Author Share Posted February 6, 2012 Actually i want to shuffle the position value between the change pagessuppose i have position in my mysql 1=home page2= about us3= service4= contact it admin chooses the service page position on 2nd then automatically about us become 3rd page i did understand how to do this.1=home page2= service3= about us4= contact Pls help if u need more info pls let me know Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2012 Share Posted February 6, 2012 If you're just re-ordering the pages, then when you submit the form you need the ID of the page you're changing and the new position. You look up the old position of that page in the database. Depending on if the page is moving forward or backward in the sort order you'll need to update the other pages to either add 1 or subtract 1 from their sort orders before you update the page you're moving. I usually draw that stuff out on paper before I write the code to make sure my logic is correct. Link to comment Share on other sites More sharing options...
nitesh Posted February 6, 2012 Author Share Posted February 6, 2012 Yes i want to reorder the page position but i didn't understand how to fetch the id of the changing position page.if iam reordering the position between 4(about) and 5(contact) how i can fetch the id of the changing page.Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2012 Share Posted February 6, 2012 You need to submit the ID of the page in the form when you submit the new position. Link to comment Share on other sites More sharing options...
nitesh Posted February 11, 2012 Author Share Posted February 11, 2012 It means when i submit the form i need two id Link to comment Share on other sites More sharing options...
justsomeguy Posted February 12, 2012 Share Posted February 12, 2012 The form should at least contain the ID of the item you are moving, and the new position. You can submit whatever other data you want, but you need at least those 2 pieces to reorder the item. Link to comment Share on other sites More sharing options...
nitesh Posted February 12, 2012 Author Share Posted February 12, 2012 The new position is changing but i don't know how to shuffle the position between the old and the new position.i can change the position for example old position 1=home page to new position 4= contact 2= about us to 2= about us 3= service to 3= service 4= contact to 1= contactold position (1)to new position (4)is working but i don't know how to change position from 4 to 1.Or if iam not right can there is another way to shuffle the value of position.Pls help Link to comment Share on other sites More sharing options...
justsomeguy Posted February 13, 2012 Share Posted February 13, 2012 Before you set the new position in the database, get the record that is currently in that position (in that example, the record in position 4). You can get the ID of the record in that position to update that record with the position of the item you were moving. It sounds like you're just switching the positions of 2 items instead of moving one up or down and having the other adjust. Link to comment Share on other sites More sharing options...
nitesh Posted February 13, 2012 Author Share Posted February 13, 2012 How i can set the id of the new position. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 13, 2012 Share Posted February 13, 2012 You update the database with an UPDATE SQL query. Link to comment Share on other sites More sharing options...
smart Posted February 14, 2012 Share Posted February 14, 2012 can u paste me some example code. Link to comment Share on other sites More sharing options...
thescientist Posted February 14, 2012 Share Posted February 14, 2012 why not look in the tutorials? that's why they are therehttp://www.w3schools.com/php/php_mysql_intro.asphttp://www.w3schools.com/sql/default.asp Link to comment Share on other sites More sharing options...
nitesh Posted February 25, 2012 Author Share Posted February 25, 2012 Problem solved thank you everyone. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.