Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-07-2010, 10:32 AM   PM User | #1
salhzmzm
New to the CF scene

 
Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
salhzmzm is an unknown quantity at this point
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".
salhzmzm is offline   Reply With Quote
Old 02-07-2010, 12:31 PM   PM User | #2
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
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 :)
JAY6390 is offline   Reply With Quote
Old 02-07-2010, 12:39 PM   PM User | #3
salhzmzm
New to the CF scene

 
Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
salhzmzm is an unknown quantity at this point
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.
salhzmzm is offline   Reply With Quote
Old 02-07-2010, 12:43 PM   PM User | #4
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
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 :)
JAY6390 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:13 AM.


Advertisement
Log in to turn off these ads.