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!
6 1403 nathj 938
Recognized Expert Contributor
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,
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
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("SE LECT primary_key FROM my_table WHERE order_number='3 '");
$result_2 = mysql_query("SE LECT primary_key FROM my_table WHERE order_number='4 ''");
$third_record = mysql_result($r esult_1 , 0 , 'primary_key');
$fourth_record = mysql_result($r esult_2 , 0 , 'primary_key');
//now set the record that currently has 'order_number' 3 to have order_number 4
mysql_query("UP DATE 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("UP DATE my_table SET order_number='3 ' WHERE primary_key='". $forth_record ."'");
//done!![/PHP]
Note that you can't just do:[PHP]
mysql_query("UP DATE my_table SET order_number='3 ' WHERE order_number='4 '");
mysql_query("UP DATE 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!
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("SE LECT primary_key FROM my_table WHERE order_number='3 '");
$result_2 = mysql_query("SE LECT primary_key FROM my_table WHERE order_number='4 ''");
$third_record = mysql_result($r esult_1 , 0 , 'primary_key');
$fourth_record = mysql_result($r esult_2 , 0 , 'primary_key');
//now set the record that currently has 'order_number' 3 to have order_number 4
mysql_query("UP DATE 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("UP DATE my_table SET order_number='3 ' WHERE primary_key='". $forth_record ."'");
//done!![/PHP]
Note that you can't just do:[PHP]
mysql_query("UP DATE my_table SET order_number='3 ' WHERE order_number='4 '");
mysql_query("UP DATE 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!
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
nathj 938
Recognized Expert Contributor
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 particular surname in a
particular town.
I can select the records fine with this syntax (testing in Oracle SQL* Plus)
SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME,
NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
|
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 tblMyTable.UniqueID =
tblMyTableTEMP.UniqueID
SET
tblMyTable.myField = tblMyTableTEMP.myField,
tblMyTable.myField2 = tblMyTableTEMP.myField2,
|
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 check these first:-
<http://developer.irt.org/script/script.htm>
|
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 must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then IF FOUND
UPDATE <TABLE> SET .... <Values entered here> ELSE
INSERT INTO <TABLE> VALUES <Values...
|
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 the necessary
records in it when testing it. I get the error "No value given for one
or more required parameters." when I try to update the database.
Can you tell me what am I doing wrong?
| |
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 northwind database that has
an employees, orders, and order details.
the following are the 3 tables in my sql database
students
schyrsem
|
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 do the update the changed
parentid in the child table fails to change. No error is given its just that
the change is not written to the Database.
When I step through the records for the child table the one I would expect
to be changed has a row...
|
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.
Example:
I have a dataadapter that contains one table with one row. I change the
value of the 'FisrtName' column in that row from Jack to John. I call
..update on the dataadapter it goes through fine. Now I change that same
column in that same row...
|
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
|
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 = ?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |