Array value print

Hello. I have a query that is returning an array like so:

while($row = $result->fetch_array(MYSQLI_ASSOC))
    			{ 
    			$row = array_map('stripslashes', $row);
				$dataArray[] = $row;
    			}
		} 
		return $dataArray;

I use a for each to print all the returned values and this is what I get as results:

As you can see I have the same class id and name repeated, because how I am getting the data with the sql query. Basically I want the class id and name to be printed once one in my top table.
I tried this outside the foreach:

                 <tr>
                  <td>" . $array['class_id'] .  "</td>
                  <td>" . $array['class_name'] .  "</td>
                 </tr>

How can I get this done?

If these fields are equal in all rows then you can get them from the first row (outside the foreach) for example:

echo $dataArray[0]['class_id'];
echo $dataArray[0]['class_name'];
1 Like

Thanks :slight_smile: Works

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.