Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

PHP update row using 2 different table. #phpmysql, i have error calling data from different

views
     
TSknightz11 P
post Oct 16 2019, 06:43 PM, updated 5y ago

New Member
*
Probation
2 posts

Joined: Oct 2019
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
post Oct 17 2019, 12:08 AM

Getting Started
**
Junior Member
160 posts

Joined: Nov 2008


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
post Oct 18 2019, 12:16 PM

New Member
*
Probation
2 posts

Joined: Oct 2019
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
post Oct 18 2019, 03:55 PM

New Member
*
Newbie
22 posts

Joined: Nov 2018
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

 

Change to:
| Lo-Fi Version
0.0124sec    0.19    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 07:14 AM