【问题标题】:How do I display PHP output next to each other? [closed]如何相邻显示 PHP 输出? [关闭]
【发布时间】:2021-07-27 12:17:54
【问题描述】:

我想将输出并排显示,有人知道我该怎么做吗?见截图:Screenshot

我找不到任何解决方案。

从数据库中获取信息并将其显示在 $result 中的部分代码。我想将所有结果并排显示,而不是在彼此下方显示(见屏幕截图)。

if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 
if(isset($_REQUEST["term"])){
    // Prepare a select statement
    $sql = "SELECT * FROM products WHERE global_name LIKE ?";
    
    if($stmt = mysqli_prepare($link, $sql)){
        // Bind variables to the prepared statement as parameters
        mysqli_stmt_bind_param($stmt, "s", $param_term);
        
        // Set parameters
        $param_term = $_REQUEST["term"] . '%';
        
        // Attempt to execute the prepared statement
        if(mysqli_stmt_execute($stmt)){
            $result = mysqli_stmt_get_result($stmt);
            
            // Check number of rows in the result set
            if(mysqli_num_rows($result) > 0){
                // Fetch result rows as an associative array
                while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
                    echo "<span><img style='width:25%;' src='../../"  . $row["image"] . "'></img><p>" . $row["global_name"] . "</p></span>";
                }
            } else{
                echo "<p>No matches found</p>";
            }
        } else{
            echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
        }
    }
     
    // Close statement
    mysqli_stmt_close($stmt);
}
 
// close connection
mysqli_close($link);
?>```

【问题讨论】:

  • @GerarddeVisser 它在我的本地主机中
  • 感谢代码更新。我已赞成通过此澄清重新提出问题。
  • @GerarddeVisser 谢谢,已经找到我的答案:)

标签: php html mysql


【解决方案1】:

您非常简单地在容器上设置display: flex。

#container {
  display: flex;
}

.item {
  margin: 5px;
  height: 100px;
  width: 100px;
  background: #369;
}
<div id="container">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-10
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 2022-01-22
    相关资源
    最近更新 更多