gpt4 book ai didi

PHP - 如何创建 4 列 (4 x 25%),然后以新的 4 列结束该行

转载 作者:行者123 更新时间:2023-11-28 15:18:04 25 4
gpt4 key购买 nike

我有一个正在进行的元素,我们可以在其中创建一个产品,该产品用 PHP 加载到首页。
但是,如果有 5 个产品,则不会创建新行。如果有 5 个产品应该显示 2 行,每行 4 个。

<section class="ICO">
<div class="one-fourth-gridtable">
<table class="grid table">
<?php
while ($subject = mysqli_fetch_assoc($subject_set)) {
$imagenavn = $subject['navn'];
$sql = "SELECT * FROM product_images WHERE image_name = '$imagenavn'";
$sth = $db->query($sql);
$result = mysqli_fetch_array($sth);
?>
<td>
<div style="border: 1px solid black; border-radius:2000px;">
<img src="data:image/jpeg;base64,<?= base64_encode($result['image']); ?>" />
</div>
<a class="action" href="<?= url_for('../show.php?id=' . h(u($subject['id']))); ?>"><?php echo h($subject['navn']); ?></a>
</td>
<?php } ?>
</table>
</div>
</section>

我尝试使用 CSS 设置表格样式:

table {
background-color: #6991ac;
width: 100%;
text-align: center;
display: inline-table;
margin-top: -5%;
}
.ICO {
max-width: 1100px;
margin: 0 auto;
}
.one-fourth-gridtable {
width: 100%;
}

最佳答案

使用此代码,您会在 4 幅图像后换行,而在 8 幅图像后循环会因 $u 而停止。如果不需要,您可以删除/更改 $u。

<?php require_once('private/initialize.php'); ?>
<?php $test = "Alle Produkter"; ?>
<?php $subject_set = find_all_subjects(); ?>
<?php $page_title = 'Forside'; ?>
<?php include(SHARED_PATH . '/staff_header.php'); ?>

<!--- Start of header --><head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="design/Design.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8" />
</head>

<!--- End of header -->

<!--- Start of section (BANNER) -->



<section class="banner">
<div class="banner-inner">
<div id="banner-image"><img src="img/cryptocurrency.png" style="margin-top:10% !important"></div>
</div>
</section>

<!--- End of section (BANNER) -->

<!--- Start of section (ICO'S) -->



<!--- End of section (ICO'S) -->


<div class="sactions">
<!-- <a class="saction" href="<?php echo url_for('/staff/subjects/new.php'); ?>">Create New Subject</a> --> </div>


<section class="ICO">
<div class="one-fourth-gridtable">
<table class="gridtable">

<?php
$i = 0;
$u = 0;
while($subject = mysqli_fetch_assoc($subject_set)) {
$imagenavn = $subject['navn'];
$sql = "SELECT * FROM product_images WHERE image_name = '$imagenavn'";
$sth = $db->query($sql);
$result=mysqli_fetch_array($sth);

$i++;
$u ++;
?>



<td>




<?php


echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ). '"/> '; ?>
<a class="action" href="<?php echo url_for('../show.php?id=' . h(u($subject['id']))); ?>"><?php echo h($subject['navn']);?></a>
<?php
if ($u > 7 ) {
break;

}
if ($i > 3) {
echo '</tr><tr>';
$i = 0;
}

?>



</td>




<?php } ?>


</table>

</div>
</section>

<?php
mysqli_free_result($subject_set);
?>

关于PHP - 如何创建 4 列 (4 x 25%),然后以新的 4 列结束该行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46718835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com