...

View Full Version : Need help with submit data to database



salhzmzm
02-07-2010, 11:32 AM
Hi

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


id
name //name of the page
ord_page //order the page
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".

JAY6390
02-07-2010, 01:31 PM
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?

salhzmzm
02-07-2010, 01:39 PM
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.

JAY6390
02-07-2010, 01:43 PM
well if you run the query

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum