Current location: Hot Scripts Forums » Other Discussions » Database » mysql multiple table update problem


mysql multiple table update problem

Reply
  #1 (permalink)  
Old 07-09-08, 04:13 AM
ordique ordique is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
mysql multiple table update problem

hi all..
i need help to solve my problem..i have a few table to update in the same time..
but dont know how to write the correct sql statement..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-09-08, 04:25 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
http://forums.mysql.com/read.php?20,85813,85813

first reply to that post gives a example
sql Code:
  1. UPDATE a
  2. INNER JOIN b USING (id)
  3. SET a.firstname='Pekka', a.lastname='Kuronen',
  4.     b.companyname='Suomi Oy',companyaddress='Mannerheimtie 123, Helsinki Suomi'
  5. WHERE a.id=1;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-09-08, 04:32 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Thread moved to Database section...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-09-08, 04:59 AM
ordique ordique is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
thanks <?Wille?>..
i will try it out..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-09-08, 05:28 AM
ordique ordique is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$result=mysql_query("UPDATE

    project1 p1, panel_detail pd, pic p, discreapancy d
    set p1.project_id='
$ncr[0]', p1.Project_Name='$ncr[1]', p1.Part_No='$ncr3', 
    p1.Description='
$ncr4', p1.Project_Date='$date', 
    p.Staff_id='
$staffid', p.stamp_no='$stampno', p.Originator='$or', p.Location_pic='$location',
    pd.Discreapancy_id='
$ncr', pd.Oper_No='$operno', pd.Drawing_No='$drawingno', pd.Rev='$rev',
    pd.Date_Cure='
$date1', pd.GRR_Batch='$grrno', pd.S_No='$sn', pd.Jig='$jigno',
    pd.Batch_Quantity='
$batchqtty', pd.JO_No='$jono',
    d.Quantity_Discrepant='
$qttydiscrpnt', d.Discreapancy_detail='$discreapancy',
    d.Others='
$notes', d.Defect_Code='$DCode'
    WHERE NCR_No='
$ncrno'"); 
i already try it..but it doesnt update inside my database..
sori i'm very weak in programing..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-09-08, 05:35 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:

$query "UPDATE
    project1 p1, panel_detail pd, pic p, discreapancy d
    set p1.project_id='
$ncr[0]', p1.Project_Name='$ncr[1]', p1.Part_No='$ncr3', 
    p1.Description='
$ncr4', p1.Project_Date='$date', 
    p.Staff_id='
$staffid', p.stamp_no='$stampno', p.Originator='$or', p.Location_pic='$location',
    pd.Discreapancy_id='
$ncr', pd.Oper_No='$operno', pd.Drawing_No='$drawingno', pd.Rev='$rev',
    pd.Date_Cure='
$date1', pd.GRR_Batch='$grrno', pd.S_No='$sn', pd.Jig='$jigno',
    pd.Batch_Quantity='
$batchqtty', pd.JO_No='$jono',
    d.Quantity_Discrepant='
$qttydiscrpnt', d.Discreapancy_detail='$discreapancy',
    d.Others='
$notes', d.Defect_Code='$DCode'
    WHERE NCR_No='
$ncrno'";

if (!
$result mysql_query($query))
{
    echo 
'<pre>';
    
printf("MySQL error: %s\n"mysql_error());
    
printf("Query: %s"$query);
    exit(
'</pre>');

Do it this way, and let MySQL tell you what the problem is. Also make sure the query string contains the expected values.

Last edited by Nico; 07-09-08 at 05:44 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-09-08, 05:46 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
It might also be usefull for you to have a look at http://dev.mysql.com/doc/refman/5.0/en/commit.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 07-09-08, 08:49 PM
ordique ordique is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
i already try it but still have error on it.it tell that
Quote:
MySQL error: Column 'NCR_No' in where clause is ambiguous
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 07-10-08, 02:44 AM
dustin56 dustin56 is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ordique View Post
MySQL error: Column 'NCR_No' in where clause is ambiguous
I believe this indicates that the field 'NCR_No' exists in more than one of the specified tables. You need to specify which table must be used in matching the where clause, or if this field must match in all tables which contain it, you have to specify that.
Like this
Code:
WHERE p.NCR_No='$ncrno'
or this
Code:
WHERE p.NCR_No='$ncrno' AND pl.NCR_No='$ncrno'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 07-10-08, 02:55 AM
ordique ordique is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
You are right dustin56..i have NCR_No in every table that i have b'cause it is foreign key.thank you for the information..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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
PHP does NOT update the mysql when rapidly sent through browser - $20 REWARD PAYPAL billyspcs PHP 2 04-22-06 02:56 PM
MySQL insert record if update fails? perleo PHP 3 01-06-06 03:21 PM
How to get PHP to input data into a MYSQL table? scl789 PHP 5 04-21-05 10:06 PM
UPDATE: MySQL Auto Backup & Export v1.1 Beyonder General Advertisements 2 03-21-05 03:05 PM
php mysql updating problem kevinb PHP 2 11-06-04 04:15 PM


All times are GMT -5. The time now is 09:16 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.