Current location: Hot Scripts Forums » Other Discussions » Database » UPDATE mysql


UPDATE mysql

Reply
  #1 (permalink)  
Old 05-13-08, 10:11 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
UPDATE mysql

is there a way to update multiple columns in one query? I can't seem to find the syntax as most tutorials are based around a single change

trying to change this insert query into an update query

PHP Code:

$query "INSERT INTO main_inventory (

                item_type, title, brand, model, serial_no, replacement_cost, quantity, kit_content, main_location ,current_location, notes
                ) VALUES (
                    '
{$item_type}','{$title}', '{$brand}','{$model}','{$serial_no}',{$replacement_cost}{$quantity}, '{$kit_content}','{$main_location}','{$current_location}','{$notes}')"
Reply With Quote
  #2 (permalink)  
Old 05-13-08, 10:34 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
it follows the syntax

SQL Code:
  1. UPDATE `tablename` SET
  2. `column1` = 'value1',
  3. `column2` = 'value2'
  4. WHERE
  5. `idcolumn` = 'something'
You need the idcolumn or some other column to verify it's the right one that you are updating. If you are wanting to update all columns, you simply remove the everything after and including the WHERE
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #3 (permalink)  
Old 05-14-08, 03:23 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Jay6390 View Post
If you are wanting to update all columns, you simply remove the everything after and including the WHERE

sorry, I don't quite follow. Are you saying there is a quicker way than listing ALL the columns in series
Reply With Quote
  #4 (permalink)  
Old 05-14-08, 03:50 AM
Wolf1994 Wolf1994 is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Russia
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
As far as I know, there is no such way in case when you wish to update specific columns with specific data.

Last edited by Wolf1994; 05-14-08 at 03:52 AM.
Reply With Quote
  #5 (permalink)  
Old 05-14-08, 06:22 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
sorry, think I misinterpreted that. You mean to update all records, not all columns
Reply With Quote
  #6 (permalink)  
Old 05-14-08, 06:28 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Moving this to Database section...
Reply With Quote
  #7 (permalink)  
Old 05-14-08, 06:38 AM
Wolf1994 Wolf1994 is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Russia
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry, I misinterpreted too. I meant records too.
If you are searching a quicker update and this is total update - i.e. update of all columns in record, you may delete all records with DELETE query and after that insert them anew with one INSERT query.
Reply With Quote
  #8 (permalink)  
Old 05-14-08, 08:29 AM
Wolf1994 Wolf1994 is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Russia
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
Rereaded the original post...
You may update several columns at once with such syntax:
SQL Code:
  1. UPDATE `your_table`SET `column1`='value1',`column2`='value2' WHERE `id`='xxx'

Last edited by UnrealEd; 05-14-08 at 08:32 AM. Reason: please use the [highlight=SQL] wrapper when posting SQL code
Reply With Quote
  #9 (permalink)  
Old 05-14-08, 08:32 AM
Wolf1994 Wolf1994 is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Russia
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
May be this link will be helpful:
http://dev.mysql.com/doc/refman/4.1/en/update.html
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL UPDATE query onlyteo PHP 4 05-06-11 04:35 PM
Php Mysql Update and Delete Form Problem mlmorg PHP 1 07-25-07 06:00 PM
Problem with a mysql table update lppa2004 PHP 2 12-24-05 05:11 AM
UPDATE: MySQL Auto Backup & Export v1.1 Beyonder General Advertisements 2 03-21-05 02:05 PM
Help with multipart update form into MySQL DB... jimb575 PHP 0 07-01-04 02:42 PM


All times are GMT -5. The time now is 05:03 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.