I have two tables inside my database. One table defines my categories and the other table includes my entries. At my output I would like to show my entries within the correct category
TABLE 1:
+----+-------+------------------+
| id | name | source_system_id |
+----+-------+------------------+
| 1 | Cat 1 | 1 |
| 2 | Cat 2 | 1 |
| 3 | Cat 3 | 1 |
| 4 | Cat 4 | 1 |
+----+-------+------------------+
TABLE 2:
+---------+---------+------+----------+--------+
| SEGMENT | FIELD | LENG | DATATYPE | REF_ID |
+---------+---------+------+----------+--------+
| Entry 1 | Field 1 | 12 | VARCHAR | 1 |
| Entry 2 | Field 2 | 15 | VARCHAR | 1 |
| Entry 3 | Field 3 | 18 | VARCHAR | 3 |
| Entry 4 | Field 4 | 18 | VARCHAR | 4 |
+---------+---------+------+----------+--------+
Output should look like:
+---------+-------+---------+---------+
| Cat 1 | Cat 2 | Cat 3 | Cat 4 |
+---------+-------+---------+---------+
| Entry 1 | | | |
| Entry 2 | | | |
| | | Entry 3 | |
| | | | Entry 4 |
+---------+-------+---------+---------+
So the id
from table 1 and the ref_id
from table 2 refer to each other. I cannot do a JOIN statement, cause table two is just a temporary table. Anyway I try to fetch all data, which works and then I want to display them as you can see above. Here is my code:
if(mysqli_num_rows($sqlCheckReference) > 0) {
$getAllSAPModules = $db_conn->getRows('dwh_metamasterdata','global_source_modules',array('where'=>array('source_system_id'=>1),'return_type'=>'all'));
if(!empty($getAllSAPModules)) {
print "<div class='row'>";
foreach ($getAllSAPModules as $sortedModule) {
print "<div class='col-md-2 col-xs-12 col-lg-2'>";
print "".$sortedModule["name"]."";
while ($res = mysqli_fetch_array($sqlCheckReference)) {
if ($res["REF_ID"]==$sortedModule["id"]) {
print "<tr>";
print "<td>".$res["SEGMENT"]."</td>";
print "</tr>";
}
}
print "</div'>";
}
print "</div>";
}
}
I receive all information from my tables, this is working so far but my code seems to be wrong, because the entries are not shown, depending on their REF_ID=id
Can someone help me out what I am doing wrong here?
EDIT:
As requested here my var_dump output from $getAllSAPModules
:
array(6) {
[0]=>
array(6) {
["id"]=>
string(1) "1"
[0]=>
string(1) "1"
["name"]=>
string(22) "Cat 1"
[1]=>
string(22) "Cat 1"
["source_system_id"]=>
string(1) "1"
[2]=>
string(1) "1"
}
[1]=>
array(6) {
["id"]=>
string(1) "2"
[0]=>
string(1) "2"
["name"]=>
string(23) "Cat 2"
[1]=>
string(23) "Cat 2"
["source_system_id"]=>
string(1) "1"
[2]=>
string(1) "1"
}
[2]=>
array(6) {
["id"]=>
string(1) "3"
[0]=>
string(1) "3"
["name"]=>
string(19) "Cat 3"
[1]=>
string(19) "Cat 3"
["source_system_id"]=>
string(1) "1"
[2]=>
string(1) "1"
}
[3]=>
array(6) {
["id"]=>
string(1) "4"
[0]=>
string(1) "4"
["name"]=>
string(18) "Cat 4"
[1]=>
string(18) "Cat 4"
["source_system_id"]=>
string(1) "1"
[2]=>
string(1) "1"
}
}