473,800 Members | 3,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating Multiple Database Rows Simultaneously

Hi,

I'm having some trouble with something that should be relatively easy. I
want to update multiple rows in one of my database tables simultaneously.
In my table I have these values:

imageID
image_order

I want to be able to modify the image_order column where imageID = imageID.

imageID | image_order
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5

I want to be able to pull these values into a form and allow the user to
edit the image_order value. So my updated table might look something like
this:

imageID | image_order
1 | 2
2 | 5
3 | 1
4 | 3
5 | 4

The problem lies in the form handling script. How can I pass multiple sets
of imageID / image_order values to an sql update query?

I can pass one set without problem. But I want the user to be able to edit
all of the image_order values from one page.

I've tried passing multiple image_order values by initialising an array and
using a foreach() loop to extract the values but I can't think of a way to
pass the corresponding imageID value. I can grab all the imageID values
again in my form handler script using an ORDER clause to ensure they are
pulled in the same order as the form script but again, I can think of no way
to combine this with the img_order array sent from my form.

How can I combine all of this data in one sql query that will update my
table?

Thanks in advance for any help.
Jul 17 '05 #1
2 10650
I noticed that Message-ID: <bm************ *******@news.de mon.co.uk> from
scott contained the following:
The problem lies in the form handling script. How can I pass multiple sets
of imageID / image_order values to an sql update query?
You can't. You'll have to write a loop and do it with multiple queries
I can pass one set without problem. But I want the user to be able to edit
all of the image_order values from one page.


You'll either have to write a loop to update all the values whether
changed or not or put a sequentially numbered checkbox beside the ones
which you want to change. Use a bit of javascript to check the box
automatically onChange for a bit of added functionality (but make it
clear the box must be checked for those without JS) Incidentally, this
simple bit of javascript had me stumped for ages until I found out that
the checkboxes would have to have a letter prefix

I use the same method to delete entries except on the first pass the
script simply writes hidden input for the records to be deleted. The
user then has to press a confirm button to complete the operation.

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2

"scott" <no@spamplease. com> wrote in message
news:bm******** ***********@new s.demon.co.uk.. .
Hi,

I'm having some trouble with something that should be relatively easy. I
want to update multiple rows in one of my database tables simultaneously.
In my table I have these values:

imageID
image_order

I want to be able to modify the image_order column where imageID = imageID.
imageID | image_order
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5

I want to be able to pull these values into a form and allow the user to
edit the image_order value. So my updated table might look something like
this:

imageID | image_order
1 | 2
2 | 5
3 | 1
4 | 3
5 | 4

The problem lies in the form handling script. How can I pass multiple sets of imageID / image_order values to an sql update query?

I can pass one set without problem. But I want the user to be able to edit all of the image_order values from one page.

I've tried passing multiple image_order values by initialising an array and using a foreach() loop to extract the values but I can't think of a way to
pass the corresponding imageID value. I can grab all the imageID values
again in my form handler script using an ORDER clause to ensure they are
pulled in the same order as the form script but again, I can think of no way to combine this with the img_order array sent from my form.

How can I combine all of this data in one sql query that will update my
table?

Thanks in advance for any help.

Fixed it:

foreach ($imageID as $key => $value)
{
mysql("$db_name ","UPDATE images SET img_order = '$value' WHERE imageID =
'$key'");
}

Just needed to create an array to pass the imageID value as the $key and the
img_order value as the $value.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2467
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... mem_id integer primary key lastname nvarchar(30) firstname nvarchar(30)
2
2149
by: Saket Mundra | last post by:
How do i input and save more than one row in a database table at a time ? Which control should i use on the form to accept input when i do not know how many rows i have to add at runtime ? -- Thank You. Saket Mundra
4
2377
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has two fields: a primary key and another holding a string. In table B there are three fields: a primary key, a foreign key (which links to the primary key in A) and other field holding a string.
4
2281
by: onecorp | last post by:
I have a SQL table comprised of 31 columns. The first column is simply an id column, the next 30 columns are labelled ,.... The numerical columns have a tinyint type and the data stored is either 1 or null. I wish to count the number of times a one appears in one column simultaneously with another column: eg count the number of times 1 appears in column and 1 also appears in column in the same row:
33
3356
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range of 20 steps) On the admin page the steps are listed, in "order" order and the user can create new steps and assign an order and all is well. The problem may come in using a renumber function which should take the steps in their current order...
3
1315
by: backups2007 | last post by:
How do I simultaneously update rows of data in a database? Should I Update it one by one? Or is there any other way to do it? $query = mysql_query("UPDATE tblProducts SET prod_code='$prod_code1'"); if($query) { $query2 = mysql_query("UPDATE tblProducts SET prod_code='$prod_code2'"); if($query2)
2
2649
by: julie18881 | last post by:
I may be being really stupid here, i have spent the last 3 hours looking round your site and some other for answers to my problem, but have not had much luck (possibly cuase my brain just isn't working today) I have EasyPHP2.0b1 Apache/MySQL server installed on my Windows XP(SP2) machine. This runs Apache 2.2.3, MySQL 5.0.27 and PHP 5.2.0 I have a PHP code filled listbox, which allows multiple selections. Actual Values are "rcd_no, cn_no"...
6
1813
by: Al Moodie | last post by:
Hi, I have a MySQL database where I want to updated multiple records. The table has two columns: product_number product_price I have a list with first entry product_price, second entry product_number
1
1941
by: Wavey | last post by:
Hi All, I have a problem with updating an Access database from a datatable. I have two rows of data in my database at the moment for testing, the first row is an ID number (primary key), the second is a name and the third is a price. I can get this data out of the database, store it in a datatable in a dataset and display the name in a listbox with the name and price displayed in textboxes. If I change the data for the second row data...
0
9695
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, 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...
0
9555
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,...
0
10287
jinu1996
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...
1
10260
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10042
tracyyun
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...
0
9099
agi2029
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...
0
6826
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();...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3770
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.