Good day, Please help guys, I have records in which if I updated table1, I have to update table2.
This is my code for update table1(which is proja)
$sqlu = mysql_query("UPDATE proja SET
pname= '$par',
amunt = '$amt',
janua = '$jan',
febru = '$feb',
march = '$mar',
april = '$apr',
prmay = '$may',
pjune = '$jun',
pjuly = '$jul',
augus = '$aug',
septe = '$sep',
octob = '$oct',
novem = '$nov',
decem = '$dec',
balan = '$bal'
WHERE proaid = $proaid
");
After I update proja, I will select tables(in which I will select the updated record of proja and other record based on projid)
if ($sqlu == true)
{ //UPDATE connected tables(total, pstotal or mototal or cototal)
$sqlb = mysql_query("SELECT *
FROM projb
INNER JOIN proja ON projb.projid = proja.projid
INNER JOIN parti ON proja.parid = parti.parid
INNER JOIN pstotal ON proja.projid = pstotal.projid
WHERE proja.projid = $projid
AND parti.parid =$parid");
if (!$sqlb){
echo 'Could not run query:' .mysql_error();
exit;
}
$row = mysql_fetch_row($sqlb);
echo " <br> pstid <br>";
$pstid = $row[0];
//Add Subtotal for PS
if ($parid==1) //Personal Services
{
while($row = mysql_fetch_array($sqlb))
{
$psamt=$row['amunt'];
$psjan=$row['janua'];
$psfeb=$row['febru'];
$psmar=$row['march'];
$psapr=$row['april'];
$psmay=$row['prmay'];
$psjun=$row['pjune'];
$psjul=$row['pjuly'];
$psaug=$row['augus'];
$pssep=$row['septe'];
$psoct=$row['octob'];
$psnov=$row['novem'];
$psdec=$row['decem'];
$psbal=$row['balan'];
//Sum rows
$totalpsamt += $psamt;
$totalpsjan += $psjan;
$totalpsfeb += $psfeb;
$totalpsmar += $psmar;
$totalpsapr += $psapr;
$totalpsmay += $psmay;
$totalpsjun += $psjun;
$totalpsjul += $psjul;
$totalpsaug += $psaug;
$totalpssep += $pssep;
$totalpsoct += $psoct;
$totalpsnov += $psnov;
$totalpsdec += $psdec;
$totalpsbal += $psbal;
If I get the total then I will update pstotal
//Update PSTOTAL
$pssql = mysql_query("UPDATE pstotal SET
psamt='$totalpsamt',
psjan='$totalpsjan',
psfeb='$totalpsfeb',
psmar='$totalpsmar',
psapr='$totalpsapr',
psmay='$totalpsmay',
psjun='$totalpsjun',
psjul='$totalpsjul',
psaug='$totalpsaug',
pssep='$totalpssep',
psoct='$totalpsoct',
psnov='$totalpsnov',
psdec='$totalpsdec',
psbal='$totalpsbal'
WHERE pstid = $pstid
;");
HOWEVER, in my update pstotal, the last record in the for loop were saved, and the records did not sum up! Please help thank you :)