This topic is locked

Compare data between 2 tables

6/3/2023 4:38:43 AM
PHPRunner General questions
A
Asak author

Hi.
i have 2 tables in a list view that i need to compare data between them:
<ol> sent list - tblEmailCampaign waiting to be send - tblContactComm
</ol>i need an indication at my list of "waiting to be send" from the "sent list" if it was Sent or UnSubscribe.
the result will be as a cell color at the "waiting to be send" (tblContactComm).
I already made it as a nested while, and got the result.
My problem is to impliment the result in "After record processed" event in my "waiting to be send" list.
The result should be as a background color of "last_campaign" column.
Right now my code doesnt do that and i get this error:
Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /home/classes/runnerpage.php:1944 Stack trace: #0 /home/classes/runnerpage.php(1931): RunnerPage->spreadRowStyle() #1 /home/classes/listpage.php(1658): RunnerPage->spreadRowStyles() #2 /home/classes/listpage.php(2213): ListPage->fillGridData() #3 /home/tblcontactcommsendit_list.php(158): ListPage->prepareForBuildPage() #4 {main} thrown in /home/classes/runnerpage.php on line 1944
This is my code:
//retrive already sent records that identify by email_id (the contact man email) ant the email subject_id.
//the sent_id indicate that it was sent or unsubscribe
$sql = "SELECT subject_id, email_id, sent_id FROM tblEmailCampaign";
$myresult = DB::Query($sql);
$myrow = array();
while ($row = $myresult->fetchAssoc()) {
$subjectId = $row['subject_id'];
$emailId = $row['email_id'];
$sentId = $row['sent_id'];
`// Fetch records from tblContactComm-the new list to be sent. here we want to see the indication from tblEmailCampaign

//the indication will be as a background color of the cell last_campaign: yellow-sent, red-unsubscribe
$sqlContactComm = "SELECT * FROM tblContactComm WHERE last_campaign != 0 AND last_campaign != '' AND last_campaign IS NOT NULL";
$myresult1 = DB::Query($sqlContactComm);
$myrow1 = array();
while ($record = $myresult1->fetchAssoc()) {
// Retrieve the last_campaign and CustomerCommID values for the current record
$currentLastCampaign = $record['last_campaign'];
$currentCustomerCommID = $record['CustomerCommID'];

// Check if the values match the tblEmailCampaign table record
if ($currentLastCampaign == $subjectId && $currentCustomerCommID == $emailId) {
// Change the background color and font color of the last_campaign field based on the sent_id field value
if ($sentId == 1) {
$record["last_campaign_css"] .= 'background: yellow;';
} elseif ($sentId == 3) {
$record["last_campaign_css"] .= 'background: red;';
}
}

$myrow1[] = $record;
}

$myrow = $myrow1;`}
anyone has an idea how to solve it ?

admin 6/6/2023

It looks like one of your SQL queries doesn't return any data and it breaks when you are trying to to access the data it supposed to return.
You need to start with the basic troubleshooting i.e. printing all the SQL queries on the page and running them manually to see which one breaks.

A
ahmed1 6/6/2023

At the end of the inner loop i get the correct $record result e.g.: 'background: yellow;'
But from this point it stuck with the error.

A
ahmed1 6/11/2023

Hi.
This issue has not been solved yet.
if someone has an idea, it cuold be grate.

admin 6/12/2023

I have answered this already - you need to print all the SQL queries on the page to make sure they all are correct and return data. The error message most likely means you are trying to access data that do not exist.