Hey i have the following code:
<html>
<table>
<table>
<thead align="left" style="display: table-header-group">
<tr>
<th>Projektnummer </th>
<th>Projektbezeichnung</th>
</tr>
</thead>
<tbody>
<?php
global $wpdb;
$result = json_decode(json_encode($wpdb->get_results("SELECT meta_value FROM wp_postmeta WHERE meta_key = '_field_projekt-laufend'")),true);
$result2 = json_decode(json_encode($wpdb->get_results("SELECT meta_value FROM wp_postmeta WHERE meta_key = '_field_projekt-abgeschlossen'")),true);
$finishedresult = array_diff($result, $result2);
$data['items'] = $finishedresult;
$total = 0;
foreach ($data['items'] as $rows) :?>
<tr class="item_row">
<td><?php echo ++$total; ?></td>
<td> <?php echo $rows['meta_value']; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</html>
The SELECT meta_value FROM wp_postmeta WHERE meta_key = '_field_projekt-laufend' returns:
Das Erste Projekt
Das Zweite Projekt
The SELECT meta_value FROM wp_postmeta WHERE meta_key = '_field_projekt-abgeschlossen' returns:
Das Erste Projekt
Now the array_diff should compare and give me the result: "Das Zweite Projekt"
But after the array_diff the array $finishedresult is empty. That cant be one array contains two different values and the other array contains 1 value. So there is no way that it can be empty.
Any Idea how to solve this problem?
Here is the new code it contains at first the version with the problem and at second the solution. array_diff cant handle the SQL query results so inserted the values in a new string array and now it works.
Here the output of the page: