.content .articles { display:flex; display: -webkit-flex; } .content .articles article{ max-width:40%; margin:1%; min-height:300px; } 
 <div class="articles"> <article> <?php for ($i = 0; $i < count($news); $i++) { echo ' <img src="img/'.$news[$i]["id"].'.jpg" alt="" title=""> <h2>'.$news[$i]["title"].'</h2> <p>'.$news[$i]["text"].'</p> <h5>'.$news[$i]["date"].'</h5> <a href="article1" title=""> Читать далее</a> ' ;} ?> </article> </div> 

How to display news from the database in different blocks? I bring the news and in the end it turns out that they are on top of each other in the same css block, and I need them to be in separate blocks.

 <?php require_once "connect.php"; function getNews ($limit) { global $mysqli; connectDB(); $result = $mysqli->query("SELECT*FROM `news` ORDER BY `id` DESC LIMIT $limit"); closeDB(); return resultToArray($result); } function resultToArray($result) { $array = array(); while(($row = $result->fetch_assoc()) != false) $array[]=$row; return $array; } 

?>

  • one
    From the above code it is impossible to make out the essence of the question Show CSS and HTML - DNS
  • Make the article tag inside the loop - G.Denis
  • Thanks, figured it out, but one more question appeared, now all 4 news are lined up in a single <div class = "articles"> block, how to make 2 news on one line displayed? - Igor
  • Understood, thank you very much for the help) - Igor

1 answer 1

 <div class="articles"> <?php foreach($news as $article){ ?> <artilce> <img src="img/' . <?=$article["id"];?> . '.jpg" alt="" title=""> <h2> . <?=$article["title"];?> . </h2> <p> . <?=$article["text"];?> . </p> <h5> . <?=$article["date"];?> . </h5> <a href="article1" title=""> Читать далее </a> </article> <?php } ?> </div>