473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to update

254 100+
Hi

I have a dynamic table of 3 cells in which fields are coming from database. I want to save the record after moving row up or down. means the last position of the data in the table to be saved. But I don't know How to do this?

Thanks!
Jan 2 '08 #1
6 1386
nathj
938 Expert 512MB
Hi,

This seems quite tricky but I think I canmanage it in 3 updates.

You need to have the display order stored in the database for this to work.

When a user clicks to move a record from position 3 to poistion 4 you need to issue three update commands on your database:

1. This will change the record with display order 3 to have a display order of -1 - or some numeric value that is not going to appear. Note using minus numbers means the data structure must allow for signed values

2. This update changes display order on the record where it is 4 to 3.

3. Then update the record with the -1 display order to have a display order of 4

The final step is to refresh the page. If all of this is done with AJAX then the user won't even notice the refresh. But that's another topic.

Have a play around with this basic outline and you will probably find a more elegant solution. If you get stuck post back with your code - in code tags and I'll take another look.

Cheers
nathj
Jan 2 '08 #2
mukeshrasm
254 100+
Hi,

This seems quite tricky but I think I canmanage it in 3 updates.

You need to have the display order stored in the database for this to work.

When a user clicks to move a record from position 3 to poistion 4 you need to issue three update commands on your database:

1. This will change the record with display order 3 to have a display order of -1 - or some numeric value that is not going to appear. Note using minus numbers means the data structure must allow for signed values

2. This update changes display order on the record where it is 4 to 3.

3. Then update the record with the -1 display order to have a display order of 4

The final step is to refresh the page. If all of this is done with AJAX then the user won't even notice the refresh. But that's another topic.

Have a play around with this basic outline and you will probably find a more elegant solution. If you get stuck post back with your code - in code tags and I'll take another look.

Cheers
nathj

Hi

I am not able to understand how to do this means issue three update commands. If you can please give some example or some code snip for that than it would be better for me to understand.

Thanks
Jan 5 '08 #3
I think mukeshrasm is talking about doing something a bit like this:

Create an extra field in your database table called 'order_number'. So each record in the table also has an order number.

Then when you want to swap record number 3 with record number 4...
[PHP]
//connect to mysql database

//now select records 3 and 4 to find out what they are
$result_1 = mysql_query("SELECT primary_key FROM my_table WHERE order_number='3'");
$result_2 = mysql_query("SELECT primary_key FROM my_table WHERE order_number='4''");

$third_record = mysql_result($result_1 , 0 , 'primary_key');
$fourth_record = mysql_result($result_2 , 0 , 'primary_key');

//now set the record that currently has 'order_number' 3 to have order_number 4
mysql_query("UPDATE my_table SET order_number='4' WHERE primary_key='". $third_record ."'");

//NB: NOTE THAT THERE ARE NOW 2 RECORDS WITH order_number 4!!!

//now change the record that was number 4 to number 3
mysql_query("UPDATE my_table SET order_number='3' WHERE primary_key='". $forth_record ."'");

//done!![/PHP]

Note that you can't just do:[PHP]
mysql_query("UPDATE my_table SET order_number='3' WHERE order_number='4'");
mysql_query("UPDATE my_table SET order_number='4' WHERE order_number='3'");[/PHP]
Because once the first query has been executed you have 2 records with order_number 3, so when the second query executes you will just get 2 records with order_number 4. Not useful. Hence the other method!
Jan 6 '08 #4
mukeshrasm
254 100+
I think mukeshrasm is talking about doing something a bit like this:

Create an extra field in your database table called 'order_number'. So each record in the table also has an order number.

Then when you want to swap record number 3 with record number 4...
[PHP]
//connect to mysql database

//now select records 3 and 4 to find out what they are
$result_1 = mysql_query("SELECT primary_key FROM my_table WHERE order_number='3'");
$result_2 = mysql_query("SELECT primary_key FROM my_table WHERE order_number='4''");

$third_record = mysql_result($result_1 , 0 , 'primary_key');
$fourth_record = mysql_result($result_2 , 0 , 'primary_key');

//now set the record that currently has 'order_number' 3 to have order_number 4
mysql_query("UPDATE my_table SET order_number='4' WHERE primary_key='". $third_record ."'");

//NB: NOTE THAT THERE ARE NOW 2 RECORDS WITH order_number 4!!!

//now change the record that was number 4 to number 3
mysql_query("UPDATE my_table SET order_number='3' WHERE primary_key='". $forth_record ."'");

//done!![/PHP]

Note that you can't just do:[PHP]
mysql_query("UPDATE my_table SET order_number='3' WHERE order_number='4'");
mysql_query("UPDATE my_table SET order_number='4' WHERE order_number='3'");[/PHP]
Because once the first query has been executed you have 2 records with order_number 3, so when the second query executes you will just get 2 records with order_number 4. Not useful. Hence the other method!
Hi
Thanks for your reply. Let me first tell you the situation actually what I am doing. I am retrieving the data(Images) from database and then displaying it in the table. From here I have given Administrator to move the selected data up or down so that it will display the modified data to the client side means to the user. Though I dont have any field in database for order no. I am swapping table row using javascript and then I am updating the modified table.

So there can be more than one swapping means I can swap row2 to row4 then I can swap row5 to row3 and row8 to row1 and so on... and then when I click the Update button it should update all the record(modified ) to the database. Or it should update the record as I swap the record one by one.

Thanks!
Jan 8 '08 #5
mukeshrasm
254 100+
Hi

I am not able to understand how to do this means issue three update commands. If you can please give some example or some code snip for that than it would be better for me to understand.

Thanks
Hi I have not tried your queries
See Thread # 5
Jan 8 '08 #6
nathj
938 Expert 512MB
Hi
Thanks for your reply. Let me first tell you the situation actually what I am doing. I am retrieving the data(Images) from database and then displaying it in the table. From here I have given Administrator to move the selected data up or down so that it will display the modified data to the client side means to the user. Though I dont have any field in database for order no. I am swapping table row using javascript and then I am updating the modified table.

So there can be more than one swapping means I can swap row2 to row4 then I can swap row5 to row3 and row8 to row1 and so on... and then when I click the Update button it should update all the record(modified ) to the database. Or it should update the record as I swap the record one by one.

Thanks!

hi,

It sounds like you've done qite a bit of work on this already and the fact that you want to be able to move rows that are not next to each other at the start shouldn't matter.

However, without a rowOrder column in the table you are making lve unnecessarily difficult. If you do not have a row order then the table order must represent the displayed order which means moving lots of data arouind in a very complex fashion. With a rowOrder colum all you need to change is information in one column.

If you allow all the changes client side and then submit them to the server on the slick of a button then this is failry straightforward.

When the page loads in its original state you knwo the order numbers against each item, so keep these somewhere. Then as they are moved around you know the new order numbers. Simply run through a loop and change each number to the negative version of the new number. Once this loop is complete update the table once more changing all the negative numbers to absolutes.

I hope that makes sense, but I'm afraid that without the rowOrder column this problem is very tricky.

Cheers
nathj
Jan 8 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
27
by: VK | last post by:
<http://www.jibbering.com/faq/#FAQ3_2> The parts where update, replacement or add-on is needed are in <update> tag. 3.2 What online resources are available? Javascript FAQ sites, please...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.