Click here to Skip to main content
15,742,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I try to add if elements after foreach to print the `else` echo, but the value become an array. How to solve it?

This is a html code.

if (count($ListCriteria > 0)){
		$i = 0;
	   foreach ($ListCriteria as $key => $value){
         if ($value['still_open']){
            echo 'date closed';

What I have tried:

This is a php code.

$ListCriteria = array();
$mySQL = 'SELECT, C.assessment_performance_id, C.title, C.description, C.justification, B.staff_sv_start_date, B.staff_sv_end_date FROM assessment_performance A INNER JOIN assessment_year B ON A.assessment_year_id = INNER JOIN assessment_performance_sectiona C ON = C.assessment_performance_id WHERE C.assessment_performance_id = "'.$data['id'].'"  ORDER BY';
$result = mysql_query($mySQL); 
if ($result){
	if (mysql_num_rows($result) > 0){ 
		while ($row = mysql_fetch_assoc($result)) {
			$ListCriteria[$row['id']]['title'] = $row['title'];
			$ListCriteria[$row['id']]['description'] = $row['description'];
			$ListCriteria[$row['id']]['justification'] = $row['justification'];	
			$ListCriteria[$row['id']]['still_open'] = false;
			if (date('Y-m-d') >= $row['staff_sv_start_start'] && date('Y-m-d') <= $row['staff_sv_end_date']){
				$ListCriteria[$row['id']]['still_open'] = true;
Updated 12-Jun-22 21:38pm
Richard Deeming 13-Jun-22 4:38am    
You have a much bigger problem. 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[^]
Richard MacCutchan 13-Jun-22 4:47am    
As far as I can see (and test) that code is correct. Maybe your question is not clear.

But you should still take careful note of the comments by Richard Deeming.

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