I want to list a string in my dropdown selection like:
Name | IntervallNumber | Intervall
This 3 values in the string need to populated from 2 MSSQL tables. Now in deep I explain the tables and what results I want in the dropdown as a string.
This is table 1:
+-------------+------+
| PK_Table1_ID| Name |
+-------------+------+
| 1 | Name1|
| 2 | Name2|
| 3 | Name3|
+-------------+------+
table 2:
+--------------+--------------+-----------------+-----------+
| PK_Table2_ID | FK_Table1_ID | IntervallNumber | Intervall |
+--------------+--------------+-----------------+-----------+
| 1 | 2 | 1 | 168 |
| 2 | 2 | 2 | 336 |
| 3 | 2 | 3 | 500 |
| 4 | 2 | 4 | 672 |
| 5 | 2 | 5 | 840 |
| 6 | 2 | 6 | 1000 |
| 7 | 3 | 1 | 168 |
| 8 | 3 | 2 | 500 |
| 9 | 3 | 3 | 1000 |
+--------------+--------------+-----------------+-----------+
I think I need multiple SQL SELECT
statements and merge them together to a string, to populate it for my dropdown.
Maybe something like this:
$sql = "SELECT Name FROM table1";
$sql2 = "SELECT IntervallNumber, Intervall
FROM table2
WHERE table1.PK_Table1_ID = table2.FK_Table1_ID";
$seperator = " | ";
$string = $sql . $seperator . $sql2;
The output string should look like in detail like:
echo "<option>" . $string . "</option>";
first select option: "Name2 | 6 | 168,336,500,672,840,100"
second select option: "Name3 | 3 | 168,500,100"
The 3rd value needs to be a string too.
The big problem is how to declare the MSSQL statements right and combine it to a enum only in the selction, not in SQL column, because the colums is integer and cant be take nvarchar
with the ,
.
Any suggestions how I can solve this?