Jump to content

how to fetch id value for position of my page


nitesh

Recommended Posts

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

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

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

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

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

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

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

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...