我和这个人在一起。如何从我的数据库中列出所有设备,他们的型号和供应商?数据以逗号分隔的形式存储在设备,模型和供应商字段中。
<?php
while ($row = mysqli_fetch_array($result)) {
$device_explode = explode(',', $row['device']);
$model_explode = explode(',', $row['model']);
$supplier_explode = explode(',', $row['supplier']);
$device = array(array($device_explode[0]), //count function? How would I do that?
array($model_explode[0]),
array($supplier_explode[0])
);
echo "<table border='1'>
<tr>
<th>Møterom</th>
<th>Romnummer</th>
<th>Lokasjon</th>
<th>Antall sitteplasser</th>
<th>Tilgjengelig utstyr</th>
<th>Bilde av rommet</th>
<th>Endre</th>
<th>Slett</th>
</tr>
<tr>
<td>".$row['name']."</td>
<td>".$row['roomnbr']."</td>
<td>".$row['location']."</td>
<td>".$row['seats']."</td>
<td>".$device[0][0]."<br>".$device[1][0]."<br>".$device[2][0]."<br></td> //also count?
<td><img src='../img/uploads/".$row['img']."' width='150px' ></td>
<td><a href='?p=editconfroomv2&id=".$row['id']."'>Endre</a></td>
<td><a href='./index.php?p=deleteconfroomdb&id=".$row['id']."' class='delete'>Slett</a></td>
</tr>
</table>";
}
?>
答案 0 :(得分:2)
可以这样做(如果我理解你的表格结构正确)。我假设webview.getSettings().setJavaScriptEnabled(true);
,$device_explode
和$model_explode
具有相同数量的元素:
$supplier_explode
答案 1 :(得分:2)
我建议循环使用标记中的数组,并使用html模板语法和替代控制结构生成输出。
我做过的一些事情[与问题没有直接关系]:
<?php
while ($row = mysqli_fetch_array($result)) {
$device_explode = explode(',', $row['device']);
$model_explode = explode(',', $row['model']);
$supplier_explode = explode(',', $row['supplier']);
//I am assuming you want to loop trough all exploded fields related to each row
$devices = [
$device_explode,
$model_explode,
$supplier_explode
];
?>
<?php while(($row = mysqli_fetch_array($result))) : ?>
<table border='1'>
<tr>
<th>Møterom</th>
<th>Romnummer</th>
<th>Lokasjon</th>
<th>Antall sitteplasser</th>
<th>Tilgjengelig utstyr</th>
<th>Bilde av rommet</th>
<th>Endre</th>
<th>Slett</th>
</tr>
<tr>
<td><?= $row['name'] ?></td>
<td><?= $row['roomnbr'] ?></td>
<td><?= $row['location'] ?></td>
<td><?= $row['seats'] ?></td>
<td>
<?php foreach ($devices as $deviceSpecs) : //Here we loop trough the first dimension fo the array ?>
<?php foreach ($deviceSpecs as $deviceSpec): //Here we loop trough the second dimension ?>
<?= $deviceSpec ?><br>
<?php endforeach; ?>
<?php endforeach; ?>
</td>
<td><img src='../img/uploads/<?= $row['img'] ?>' width='150px' ></td>
<td><a href='?p=editconfroomv2&id=<?= $row['id'] ?>>Endre</a></td>
<td><a href='./index.php?p=deleteconfroomdb&id=<?= $row['id'] ?>' class='delete'>Slett</a></td>
</tr>
</table>
<?php endwhile; ?>