Seeking some assistance please.
I have inserted a custom button that will add selected records to another table but the table needs to be checked for existing records.
The unique key constraint utilizes 3 fields however; studentid, current_year and subject. So there should be a check on these three columns.
Below are the codes i tried but don't seem to work.
Some help will be greatly appreciated.
Thanks in advance!
$rsEx = DB::Query("select `record_number` from Subject_Marks where `studentid` = ".$CustRecord["studentid"]." AND `School_Yr` = ".$CustRecord["Current_Year"]." AND `Subject` = ".$CustRecord["Subject"]."" );
while($CustRecord = $button->getNextSelectedRecord())
{
$rsEx = DB::Query("select `record_number` from Subject_Marks where `studentid` = ".$CustRecord["studentid"]." AND `School_Yr` = ".$CustRecord["Current_Year"]." AND `Subject` = ".$CustRecord["Subject"]."" );
$CustData = $rsEx->fetchNumeric();
IF(IsSet($CustData[0])){
$ResultDetail .= "<tr> <td> ".$CustRecord["studentid"]."</td> <td> ".$CustRecord["first_name"]."</td> <td> Record already exists.</td> </tr>";
}ELSE{
//record does not exists. Add it.
DB_Exec("insert into customer_two (studentid, first_name, last_name)
values (".$CustRecord["studentid"].", '".$CustRecord["last_name"]."', '".$CustRecord["first_name"]."')");
$ResultDetail .= "<tr> <td> ".$CustRecord["studentid"]."</td> <td> ".$CustRecord["first_name"]."</td> <td> Record Added.</td> </tr>";
}
}
$result["result"] = $ResultHead.$ResultDetail.$ResultFooter;
I have inserted a custom button that will add selected records to another table but the table needs to be checked for existing records.
The unique key constraint utilizes 3 fields however; studentid, current_year and subject. So there should be a check on these three columns.
Below are the codes i tried but don't seem to work.
Some help will be greatly appreciated.
Thanks in advance!
$rsEx = DB::Query("select `record_number` from Subject_Marks where `studentid` = ".$CustRecord["studentid"]." AND `School_Yr` = ".$CustRecord["Current_Year"]." AND `Subject` = ".$CustRecord["Subject"]."" );
while($CustRecord = $button->getNextSelectedRecord())
{
$rsEx = DB::Query("select `record_number` from Subject_Marks where `studentid` = ".$CustRecord["studentid"]." AND `School_Yr` = ".$CustRecord["Current_Year"]." AND `Subject` = ".$CustRecord["Subject"]."" );
$CustData = $rsEx->fetchNumeric();
IF(IsSet($CustData[0])){
$ResultDetail .= "<tr> <td> ".$CustRecord["studentid"]."</td> <td> ".$CustRecord["first_name"]."</td> <td> Record already exists.</td> </tr>";
}ELSE{
//record does not exists. Add it.
DB_Exec("insert into customer_two (studentid, first_name, last_name)
values (".$CustRecord["studentid"].", '".$CustRecord["last_name"]."', '".$CustRecord["first_name"]."')");
$ResultDetail .= "<tr> <td> ".$CustRecord["studentid"]."</td> <td> ".$CustRecord["first_name"]."</td> <td> Record Added.</td> </tr>";
}
}
$result["result"] = $ResultHead.$ResultDetail.$ResultFooter;