以 2 列显示行

发布于 2025-01-15 23:02:33 字数 1789 浏览 3 评论 0原文

我想在 2 列上显示我的行,

但由于某种原因,它只在 2 行上显示第一个条目。(1 行上的“name”/其他行上的“grouped_id”。 不是我的数据库的所有条目。

我错过了 $row= 所知道的一些事情。

你能帮助我吗 ?我想在每一行显示“名称”
“grouped_id”:

我的代码

<title>TITLE</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@700;800;900&display=swap" rel="stylesheet">
<style>
body {background-color: #000000;}
table {
    background-color: #000000;
    border-collapse: collapse;
    width: 100%;

}
table, .table {
    color: #fff;
      font-family: "Montserrat", sans-serif;
  font-size: 18px;
  font-weight:800;
font-weight:Extra-bold;
}
tr:nth-child(even) {
background-color: #60451e;
}
</style>
<div class="container"> 
    <div class="row">
        <?php
        include_once("inc/db_connect.php");
        $sqlQuery = "SELECT  name, GROUP_CONCAT(id ORDER BY id SEPARATOR ' | ') as grouped_id  FROM developers GROUP BY name";
        $resultSet = mysqli_query($conn, $sqlQuery) or die("database error:". mysqli_error($conn));
        ?>
        <table id="editableTable" class="table table-bordered">

            <tbody>
<?php
 
// represents your database rows
$rows = mysqli_fetch_array($resultSet);
 
$length = count($rows);
$halfIndex = ceil($length / 2);
 
$currentRow = 0;
while ($currentRow < $halfIndex) {
    $leftIndex = $currentRow;
    $rightIndex = $halfIndex + $currentRow;
 
    $leftColumn = $rows[$leftIndex] ?? '--';
    $rightColumn = $rows[$rightIndex] ?? '--';
 
    echo "<tr>";
    echo "<td>{$leftColumn}</td>";
    echo "<td>{$rightColumn}</td>";
    echo "</tr>";
 
    $currentRow++;
}
?>
            </tbody>
        </table>    
  </div>
</div>

I would like to display my row on 2 columns,

but for a reason it is only displaying the first entry on 2 rows.('name' on 1 row /'grouped_id' other row.
Not all entries of my database.

I missed something know with $row=.

Can you help me ? I would like display 'name'
'grouped_id' on each row:

my code

<title>TITLE</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@700;800;900&display=swap" rel="stylesheet">
<style>
body {background-color: #000000;}
table {
    background-color: #000000;
    border-collapse: collapse;
    width: 100%;

}
table, .table {
    color: #fff;
      font-family: "Montserrat", sans-serif;
  font-size: 18px;
  font-weight:800;
font-weight:Extra-bold;
}
tr:nth-child(even) {
background-color: #60451e;
}
</style>
<div class="container"> 
    <div class="row">
        <?php
        include_once("inc/db_connect.php");
        $sqlQuery = "SELECT  name, GROUP_CONCAT(id ORDER BY id SEPARATOR ' | ') as grouped_id  FROM developers GROUP BY name";
        $resultSet = mysqli_query($conn, $sqlQuery) or die("database error:". mysqli_error($conn));
        ?>
        <table id="editableTable" class="table table-bordered">

            <tbody>
<?php
 
// represents your database rows
$rows = mysqli_fetch_array($resultSet);
 
$length = count($rows);
$halfIndex = ceil($length / 2);
 
$currentRow = 0;
while ($currentRow < $halfIndex) {
    $leftIndex = $currentRow;
    $rightIndex = $halfIndex + $currentRow;
 
    $leftColumn = $rows[$leftIndex] ?? '--';
    $rightColumn = $rows[$rightIndex] ?? '--';
 
    echo "<tr>";
    echo "<td>{$leftColumn}</td>";
    echo "<td>{$rightColumn}</td>";
    echo "</tr>";
 
    $currentRow++;
}
?>
            </tbody>
        </table>    
  </div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2025-01-22 23:02:33

看一下官方文档 https://www.php .net/manual/en/mysqli-result.fetch-array.php
或者在这里查看简短摘要 https://www.w3schools.com/php/func_mysqli_fetch_array.asp< /a>

mysqli_fetch_array 的结果是一个数组的数组:一个样本列表,其中每个样本都是查询表中的字段列表。

Have a look at the official documentation https://www.php.net/manual/en/mysqli-result.fetch-array.php
or here for a brief summary https://www.w3schools.com/php/func_mysqli_fetch_array.asp

The result of mysqli_fetch_array is a an array of array: a list of samples where each sample is a list of fields from the query table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文