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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need help with submit data to database

    Hi

    Let's say that I have table in my database called "Pages" and this table contains these fields :

    1. id
    2. name //name of the page
    3. ord_page //order the page
    4. visible //0 : not visible, 1:visible


    My proplem is that when a user want to submit new page with these data, for example: (about, 1, 1) , and maybe there is a page ( row) in database have the same value in "ord_page" like "index", so I need a solution that can solve this proplem.

    Further info, I need some solution to update the "ord_page" field in my database when a user update, insert or delete any page (row) from database so I can order the resaults (SELECT * FROM pages ORDER BY ord_page) with this field "ord_page".

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    So you want to insert a row with a certain page order number, so say you have
    1, 2, 3, 4, 5
    in your database for the orders, and you put an order 3 in you want 3, 4, 5 to become 4, 5, 6 respectively?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JAY6390 View Post
    So you want to insert a row with a certain page order number, so say you have
    1, 2, 3, 4, 5
    in your database for the orders, and you put an order 3 in you want 3, 4, 5 to become 4, 5, 6 respectively?
    I mean, if we have in "ord_page" field 1,2,3 and the user submit a 3 so we have 1, 2, 3, 3 now and this is a proplem because I want to order pages using this field.

    I want to solve this proplem.

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    well if you run the query
    Code:
    UPDATE Pages SET ord_page = ord_page + 1 WHERE ord_page >= 'X'
    changing X to ord_page that is going to be inserted with the new post, and then inserting the new page. What that will do is make all the orders shift up one and allow your page to be inserted at that number
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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