If primary key in array availble but no foreign key in many array echo a comment
If primary key in array availble but no foreign key in many array echo a comment
(OP)
I have 2 arrays that have a one to many relationship. The one side array has the meeting information and the many sided array contains the handout links. The meeting info is loaded before the handouts, which are loaded days before. The primary and foreign key is 'meetdate'. As you can see there are no handouts available for "meetdate"=>"2019-08-28".
I display the meeting info in a html table. My difficulty is showing the user if no handouts are available then leave the message "No handouts available at this time".
Here is my code. The code between the commented section is where I am having difficulty. I have tried different if and elseif combinations without success. My last attempt below was to check if 'meetdate' exists in one array but not the other. As
Any help or suggestions are appreciated.
I display the meeting info in a html table. My difficulty is showing the user if no handouts are available then leave the message "No handouts available at this time".
Here is my code. The code between the commented section is where I am having difficulty. I have tried different if and elseif combinations without success. My last attempt below was to check if 'meetdate' exists in one array but not the other. As
CODE --> PHP
<?php $meetinfo_array = array( array("meetdate"=>"2019-06-18","topic"=>"Hypertension","speaker"=>"Bob"), array("meetdate"=>"2019-07-10","topic"=>"Myocardial Infarction","speaker"=>"Jane"), array("meetdate"=>"2019-08-28","topic"=>"Cancer","speaker"=>"Pete") ); $handout_array = array( array("meetdate"=>"2019-06-18","type"=>"Handout 6 slides per page","filename"=>"htn_6.pdf"), array("meetdate"=>"2019-06-18","type"=>"References","filename"=>"htn_ref.pdf"), array("meetdate"=>"2019-06-18","type"=>"Appendix","filename"=>"htn_app.pdf"), array("meetdate"=>"2019-07-10","type"=>"Handout 6 slides per page","filename"=>"mi_6.pdf"), ); echo '<table>'; foreach($meetinfo_array as $result){ echo '<tr>'; echo '<td>'. "Date: " .date('F d, Y', strtotime($result['meetdate'])). '</td>'; $meetdate = $result['meetdate']; echo '</tr>'; echo '<tr>'; echo '<td>'. "Topic: " .$result['topic']. '</td>'; echo '</tr>'; echo '<tr>'; echo '<td>'. "Speaker: " .$result['speaker']. '</td>'; echo '</tr>'; foreach($handout_array as $row){ if ($row['meetdate'] === $meetdate) { echo '<tr>'; echo '<td>'.'<a href="../../handouts/' . $row['filename']. '">' . $row['type'] . '</a>' . '</td>'; echo '</tr>'; } /** ************************************ elseif ((in_array($meetdate, $meetinfo_array, true) && (!in_array($meetdate, $handout_array, true)))) { echo '<tr>'; echo '<td>' ."Handouts not available at this time.". '</td>'; echo '</tr>'; } ***************************************/ } echo '<tr>'; echo '<td>' ." ". '</td>'; echo '</tr>'; } echo '</table>'; ?>
Any help or suggestions are appreciated.
RE: If primary key in array availble but no foreign key in many array echo a comment
To maintain your logic you can add a control variable, and act on it after the foreach loop is done.
CODE
----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.
Web & Tech
RE: If primary key in array availble but no foreign key in many array echo a comment