我希望你过得愉快。我有一个拖放系统
在我的网站上,基本上它是一个居民计划的网站。如果你想做一个新的
计划你有一个象形图(图标)列表,你拖动代表活动的图标
每个居民旁边。现在插入完美有效但显示数据没有。
这是我的表结构:
1。方案
2。居民(= bewoners):
第3。活动(=象形图):
这就是我显示数据所需要的。如您所见,“方案”表格为 主要的一个。现在我要显示方案,它将通过HTML表发生。让我跳一下 直接进入代码:Rangnr基本上是活动(图标)
的地方<div id="MainDiv">
<div id="ListBewoners">
<table id="ListBewonersUL">
<?php
$sql = "SELECT *
FROM ActiviteitenSchema A, Bewoners B
WHERE A.Bewoner = B.IDBewoner
GROUP BY Bewoner
";
$sqlrang1 = "SELECT * FROM ActiviteitenSchema A, Pictogrammen P
WHERE P.IDPictogram = A.Activiteit AND Rangnr = 1
AND DatumAangemaakt = $datumAangemaakt";
$sqlrang2 = "SELECT * FROM ActiviteitenSchema A, Pictogrammen P
WHERE P.IDPictogram = A.Activiteit AND Rangnr = 2
AND DatumAangemaakt = $datumAangemaakt";
$sqlrang3 = "SELECT * FROM ActiviteitenSchema A, Pictogrammen P
WHERE P.IDPictogram = A.Activiteit AND Rangnr = 3
AND DatumAangemaakt = $datumAangemaakt";
$sqlrang4 = "SELECT * FROM ActiviteitenSchema A, Pictogrammen P
WHERE P.IDPictogram = A.Activiteit AND Rangnr = 4
AND DatumAangemaakt = $datumAangemaakt";
$sqlrang5 = "SELECT * FROM ActiviteitenSchema A, Pictogrammen P
WHERE P.IDPictogram = A.Activiteit AND Rangnr = 5
AND DatumAangemaakt = $datumAangemaakt";
$sqlrang6 = "SELECT * FROM ActiviteitenSchema A, Pictogrammen P
WHERE P.IDPictogram = A.Activiteit AND Rangnr = 6
AND DatumAangemaakt = $datumAangemaakt";
$sqlrang7 = "SELECT * FROM ActiviteitenSchema A, Pictogrammen P
WHERE P.IDPictogram = A.Activiteit AND Rangnr = 7
AND DatumAangemaakt = $datumAangemaakt";
$res = mysqli_query($mysqli, $sql);
$resRang1 = mysqli_query($mysqli, $sqlrang1);
$resRang2 = mysqli_query($mysqli, $sqlrang2);
$resRang3 = mysqli_query($mysqli, $sqlrang3);
$resRang4 = mysqli_query($mysqli, $sqlrang4);
$resRang5 = mysqli_query($mysqli, $sqlrang5);
$resRang6 = mysqli_query($mysqli, $sqlrang6);
$resRang7 = mysqli_query($mysqli, $sqlrang7);
while ($row = mysqli_fetch_assoc($res)){
?>
<tr>
<td><?php echo $row["IDBewoner"] ?></td>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row['Foto']) . '" width="90" height="90">' ?></td>
<?php
$row1 = mysqli_fetch_assoc($resRang1);
$row2 = mysqli_fetch_assoc($resRang2);
$row3 = mysqli_fetch_assoc($resRang3);
$row4 = mysqli_fetch_assoc($resRang4);
$row5 = mysqli_fetch_assoc($resRang5);
$row6 = mysqli_fetch_assoc($resRang6);
$row7 = mysqli_fetch_assoc($resRang7);
?>
<!-- Rang1 Controle -->
<?php
if(!empty($row1)) {
?>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row1['Pictogram']) . '" width="90" height="90">' ?></td>
<?php
} else {
?>
<td><?php echo "Empty"; ?></td>
<?php
}
?>
<!-- Rang2 Controle -->
<?php
if(!empty($row2)) {
?>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row2['Pictogram']) . '" width="90" height="90">' ?></td>
<?php
} else {
?>
<td><?php echo "Empty2"; ?></td>
<?php
}
?>
<!-- Rang3 Controle -->
<?php
if(!empty($row3)) {
?>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row3['Pictogram']) . '" width="90" height="90">' ?></td>
<?php
} else {
?>
<td><?php echo "Empty3"; ?></td>
<?php
}
?>
<!-- Rang4 Controle -->
<?php
if(!empty($row4)) {
?>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row4['Pictogram']) . '" width="90" height="90">' ?></td>
<?php
} else {
?>
<td><?php echo "Empty4"; ?></td>
<?php
}
?>
<!-- Rang5 Controle -->
<?php
if(!empty($row5)) {
?>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row5['Pictogram']) . '" width="90" height="90">' ?></td>
<?php
} else {
?>
<td><?php echo "Empty5"; ?></td>
<?php
}
?>
<!-- Rang6 Controle -->
<?php
if(!empty($row6)) {
?>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row6['Pictogram']) . '" width="90" height="90">' ?></td>
<?php
} else {
?>
<td><?php echo "Empty6"; ?></td>
<?php
}
?>
<!-- Rang7 Controle -->
<?php
if(!empty($row7)) {
?>
<td><?php echo '<img src="data:image/jpeg;base64,' . base64_encode($row7['Pictogram']) . '" width="90" height="90">' ?></td>
<?php
} else {
?>
<td><?php echo "Empty7"; ?></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</div>
</div>
结果,这是数据的样子:
但问题是,这是我插入它们的方式(抱歉有点css问题):
问题:插入的数据非常好插入,我在数据库中检查了它们,但是显示了
他们没有按照应有的方式工作。是否有更好的方法来取桌8次?由于
显然我的代码并没有真正起作用。
答案 0 :(得分:1)
首先,正如一些评论指出的那样,您可以在一个查询中获取数据并循环遍历它。
所有你需要保留插入时的顺序是使用ORDER BY
子句:
SELECT P.Pictogram, A.Rangnr
FROM ActiviteitenSchema A
INNER JOIN Pictogrammen P ON P.IDPictogram = A.Activiteit
WHERE DatumAangemaakt = $datumAangemaakt
ORDER BY A.Rangnr ASC
这样你可以在循环中写出结果:
while ($row = mysqli_fetch_assoc($res)) {
if(!is_null($row["Pictogram"])) {
?>
<td><img src="data:image/jpeg;base64,<?php echo base64_encode($row['Pictogram']) ?>" width="90" height="90"></td>
<?php
} else {
?>
<td>Empty <?php echo $row["Rangnr"] ?></td>
<?php
}
}