Click here to Skip to main content
15,877,384 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Quote:

I have data value from 2 years which is 2021 and 2022 with same staff_id. I have display all data from year 2022(Now) and how do I get data from year 2021 with same staff_id but different application_id and different year_id.I give a simple example according to my problems. The problem is how to get value for third 'td' which is the answer in from data value 2022?


What I have tried:

HTML
<table>
<tr>
  <th> Staff Name </th>
  <th> Score Year 2021 </th>
  <th> Score Year 2022 </th>
</tr>
<tr>
 <td>Mimi</td>
 <?php 
  foreach ($scoreYear as $key => $value){
   if (array_key_exists($key,$value['assessment'])){
   echo  '<td>'.$value['assessment'][$key]['score_a'].'</td>';
   echo  '<td>'.$value['assessment'][$key]['score_a'].'</td>';
   }
  }
  ?>
</tr>


</table>


PHP
$filter['year'] = date('Y');

$scoreYear = array();
$mySQL = 'SELECT id, year_assessment FROM assessment_year WHERE type_assessment = "Performance Assessment" AND year_assessment = "'.$filter['year'].'"';
$result = mysql_query($mySQL);
  if (mysql_num_rows($result) > 0){
      while ($row = mysql_fetch_assoc($result)){
          $scoreYear [$row['id']] = $row['year_assessment'];
      }
}
Posted
Updated 10-Aug-22 22:13pm
v2
Comments
Richard Deeming 11-Aug-22 4:35am    
Based on that snipped, the rest of your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900