Have a SQL table like this:
Titles Device1 Device2 Device3
Title1 inputA inputA inputB
Title2 inputA inputB inputC
Title3 inputB inputB inputB
I want the values inputA, inputB, inputC to each appear once in each row with their corresponding fields, Device1, Device2, Device3, appearing as an array following the "input" values like this:
Titles header1 header2 header3
Title1 inputA: inputB:
Device1 Device3
Device2
Title2 inputA: inputB: inputC:
Device1 Device2 Device3
Title3 inputB:
Device1
Device2
Device3
This is what I've got so far after a custom header and SELECT statement:
$myquery = $mysqli->query ($sqlSelect);
if ($myquery = $mysqli->query ($sqlSelect)) {
while($row = mysqli_fetch_assoc($myquery)){
$format=array();
foreach ($row as $key => $val) {
switch($key) {
case "Device1":
case "Device2":
case "Device3":
$format[$val] = "<br>".$key;
break;
}
}
printf ("<tr><td>%s</td>", $row["Titles"]);
foreach ($format as $key => $val) {
printf ("<td>$key:<br/>$val</td>");
}
printf ("</tr>");
}
But don't know how to get all "Device" fields to display with their corresponding values. Looks like this:
Titles header1 header2 header3
Title1 inputA: inputB:
Device1 Device3
Title2 inputA: inputB: inputC:
Device1 Device2 Device3
Title3 inputB:
Device1
The only time more than one Device field appeared in a cell was when there were no values in a row with a title. Missing something before break
? A while
statement?