Outline ·
[ Standard ] ·
Linear+
PHP update row using 2 different table. #phpmysql, i have error calling data from different
TSknightz11 P
|
Oct 16 2019, 06:43 PM, updated 5y ago
|
New Member
|
All the otai coding master. i need help. if i want to put a condition to this query like status has to be '3' then only ttlpoints+$points will execute. but status is from earn_act table. and the data that i want to update is from csp table this is the code i have right now...
if ($row[`xid']! = ' ') { $sql_update_csp= "UPDATE csp SET ttlpoints =(ttlpoints+$point) where xid='$xid'" ; how do i fix this? i tried putting AND after where like this where xid='$xid' and earn_act. status='3'; but it doesnt work
|
|
|
|
RookieDaddy
|
Oct 17 2019, 12:08 AM
|
Getting Started
|
you need to join the 2 tables in your UPDATE statement. e.g. in MSSQL Syntax CODE UPDATE Commisison SET rate = 0.15 FROM Commission INNER JOIN Employee ON Commission.EmployeeID = Employee.EmployeeID WHERE Commission.EmployeeID = '000018' AND Employee.Status = 'Active';
you can adapt to your database SQL syntax.
|
|
|
|
TSknightz11 P
|
Oct 18 2019, 12:16 PM
|
New Member
|
QUOTE(RookieDaddy @ Oct 17 2019, 12:08 AM) you need to join the 2 tables in your UPDATE statement. e.g. in MSSQL Syntax CODE UPDATE Commisison SET rate = 0.15 FROM Commission INNER JOIN Employee ON Commission.EmployeeID = Employee.EmployeeID WHERE Commission.EmployeeID = '000018' AND Employee.Status = 'Active';
you can adapt to your database SQL syntax. so according to your code.. the Commission and Employee needs to have the same primary key? or if not will i still be able to call the data?
|
|
|
|
funcode
|
Oct 18 2019, 03:55 PM
|
New Member
|
no needs to have the same primary key just need same field data
example
ON csp.xid = earn_act.uid //earn_act.uid have same data xid
This post has been edited by funcode: Oct 18 2019, 04:42 PM
|
|
|
|