我是一个PHP新手,所以请放松点. 目前我有一个简单的SQL表,我试图列出DIV(CSS语音泡泡)内部的内容. 我面临的唯一问题是,它似乎将迪夫堆叠在另一个上面,给人一种只显示一行表的错觉. 如果我在语音气泡DIV输出回声下回声出现一个断点,它只添加一行,因此我需要放入大约20行才能将语音气泡分开.我已经try 了几天,试图在语音泡泡DIV中添加一个行断点,这样每个表行都有自己的单独的语音泡泡,但没有任何结果.如有任何帮助,我们将不胜感激.Tia

 <?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT first_name, review, initial, approved FROM test";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
    while ($row = $result->fetch_assoc()) {
        $fielf4name = $row ['approved'];
        $field1name = $row["first_name"];
        $field2name = $row["initial"];
        $field3name = $row["review"];

        if ($row ['approved'] == "1")
        {
            echo '<div class="speech-bubble">', $field1name, ' ', $field2name, ' <br /><br />' , $field3name, ' </div> ' ;
        }
    
}

/*freeresultset*/
$result->free();
}

?> 

语音泡泡CSS(如果需要)

.speech-bubble {
   width: 70%; 
   height: auto; 
   background: #6d8c33;
   position: absolute;
   left:100px;
   -moz-border-radius: 10px; 
   -webkit-border-radius: 10px; 
   border-radius: 10px;
}
.speech-bubble:before {
   content:"";
   position: absolute;
   width: 0;
   height: 0;
   border-top: 13px solid transparent;
   border-right: 26px solid #6d8c33;
   border-bottom: 13px solid transparent;
   margin: 13px 0 0 -25px;
}

我曾try 在DIV中使用断点,但不断出现语法错误.

推荐答案

听起来像是您试图以HTML形式在语音泡泡式DIV内显示一个SQL表的内容.如果您遇到DIV相互堆叠的问题,那么很可能是CSS或布局问题,而不是PHP或SQL问题.

语音泡泡样式和布局的CSS:

/* CSS for the speech bubble */
.speech-bubble {
    position: relative;
    background-color: #f0f0f0;
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 20px; /* Adjust as needed to add space between speech bubbles */
}

/* CSS to clear the float and create separation between speech bubbles */
.clearfix::after {
    content: "";
    clear: both;
    display: table;
}
<?php
// Assuming you have retrieved the data from your MySQL table into an array called $rows

// Loop through each row of the MySQL table
foreach ($rows as $row) {
    // Output a speech bubble DIV for each row
    echo "<div class='speech-bubble'>";
    echo "<p>" . $row['column_name'] . "</p>"; // Replace 'column_name' with the actual column name from your table
    echo "</div>";

    // Output a line break to separate the speech bubble DIVs
    echo "<br>";
}
?>

此CSS将使用填充、边界半径和背景色来为语音气泡DIV设置样式,并添加页边底以在语音气泡之间创建空间..clearFix类确保每个演讲气泡从新行开始.

确保调整CSS类和属性以匹配您特定的样式偏好和布局要求.

Php相关问答推荐

如何在数据库中添加注册表单中的动态新行?

有什么方法可以阻止WordPress主题升级通知吗?

MySQLi是否在事务错误时删除保存点(并且仅删除保存点)?

在内部API请求之后,在响应客户端之前,是否忘记了PHP中的Header()?

WooCommerce管理订单列表自定义列不显示值

WooCommerce HPOS管理订单列表中带有订单元数据的定制列

在PHP中读取JSON

只收取WooCommerce中最高的运费

使用ESI的Symfony Sulu清漆

在WP工具中页面加载时可短暂看到的JavaScript生成的字段

限制联系人页面仅允许在WooCommerce中登录的用户

WooCommerce 中一件免费产品的数量折扣

加载 Xdebug PHP 7.4.0 失败

添加或删除优惠券后自动刷新 WooCommerce checkout 表单字段

为WooCommerce中的运输方式ID设置必填的 checkout 订单备注字段

在 Botiga 主题模板中添加复选框到政策行.Woocommerce

WooCommerce单个产品页面上启用额外选项卡的产品元框字段

同一页面上多个组件的 Livewire 分页问题

同时执行odbc_execute、odbc_fetch_row和odbc_result

Laravel Docker 几个数据库