Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    increment record order

    Hello!

    having issues with this function, mainly the logic behind it I guess.

    I've got a very simple CMS, and order the pages to be displayed on the front end with a TinyInt field in the db.

    PHP Code:
        Function SetPageOrder($numSectionID,$numPageOrder){

            
    // Check Page Order and Increment if needed
            
    $result mysql_query("SELECT Id,PageOrder FROM pages WHERE ParentID = " $numSectionID );
            while (
    $row mysql_fetch_array($result)){
                If(
    $numPageOrder == $row['PageOrder'] || $numPageOrder $row['PageOrder']){
                    
    mysql_query"UPDATE PageOrder SET PageOrder = PageOrder + 1 WHERE Id=" $row['Id'] );
                }
            }
        } 
    what i'm trying to do here, is if i create a new page and set the page order to 1 for example, I would like all the other pages in that section to bump up a number. I thought this function would work, but no go.

    any ideas would be great,

    thanks in advance for your time!
    -Ken

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    you will need to select all the records that are equal to 1 and more than 1

    for example

    Code:
    SELECT * FROM PAGES WHERE PAGE_ORDER =< 1
    then loop through all records and update them accordingly
    for example

    Code:
    UPDATE PAGES
    SET PAGE_ORDER = $row['PAGE_ORDER'] + 1
    Cheers
    Ess


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •