【问题标题】:Bootstrap columns in a php while loop not workingphp while循环中的引导列不起作用
【发布时间】:2021-03-17 19:27:13
【问题描述】:

目前,我的产品显示在一列中,但我希望它们显示在 3 或 4 列网格中。这是我到目前为止的代码。

        $result = mysqli_query($this->dbConnect, $sqlQuery);
        $totalResult = mysqli_num_rows($result);
        $searchResultHTML = '';

        if ($totalResult > 0) {
            while ($row = mysqli_fetch_assoc($result)) {
                $searchResultHTML .= '
                    <div class="col-md-4">
                            <article class="aa-properties-item">
                                <a href="#" class="aa-properties-item-img">
                                    <img src="img/preventas/' . $row['RutaImagen'] . '"  alt="img" class="img-responsive" >
                                </a>
                                <div class="aa-tag for-sale">
                                    Entrega: Inmediata
                                </div>
                                <div class="aa-properties-item-content">
                                    <div class="aa-properties-info">
                                        <span>' . $row['Num_Habitaciones'] . ' Cuartos</span>
                                        <span>' . $row['Num_Banios'] . ' Baños</span>
                                        <span>Desde ' . $row['Metros_Cuadrados_Desde'] . ' m<sup>2</sup></span>
                                        <span>Hasta ' . $row['Metros_Cuadrados_Hasta'] . ' m<sup>2</sup></span>
                                    </div>
                                    <div class="aa-properties-about">
                                        <h3>10 Departamentos</h3>
                                        <p>En una elegante torre de 18 pisos rodeados de terrazas con jardines y áreas comunes incomparables que brindan increíbles espacios abiertos para vivir y crear experiencias.</p>
                                    </div>
                                    <div class="aa-properties-detial">
                                        <span class="aa-price">
                                            Desde $' . $row['Precio'] . ' 
                                        </span>
                                        <a href="#" class="aa-secondary-btn"><button type="button" class="btn btn-primary">Ver Detalles</button></a>
                                    </div>
                                </div>
                            </article>
                    </div>';
            }
        } else {
            $searchResultHTML = '<h3>No se ha encontrado ningún resultado..</h3>';
        }
        return $searchResultHTML;
    }
}

【问题讨论】:

  • 请向我们展示生成的 HTML 和 CSS。我不明白这个问题与 PHP 有什么关系。

标签: php html bootstrap-4


【解决方案1】:

你可以试试这个

 function foo($id){

  ...
  $results = [];

  $datas= mysqli_query(...);
  while ($result = mysqli_fetch_assoc($datas)) {
    $results[] = $result;   
  }

  return $results;
}

$results= foo($id);

foreach($results as $result) {
    //use $result
}

【讨论】:

  • 请解释这是什么。你为什么不使用fetch_all()?它是如何回答问题的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 2012-04-15
  • 1970-01-01
  • 2016-10-21
相关资源
最近更新 更多