File: /home/wekawqug/ndondocup.sisihub.co.tz/testimony.php
<div class="col-lg-6">
<div class="row">
<?php
$where = '';
$count = 0; // Initialize counter
if(isset($_GET['q'])){
$where = " and md5(p.category_id) = '{$_GET['q']}' ";
}
$news = $conn->query("SELECT p.*, c.category FROM post_list p INNER JOIN category_list c ON c.id = p.category_id WHERE p.category_id = 7 ORDER BY unix_timestamp(date_published) DESC LIMIT 4");
if($news->num_rows > 0):
$count = 0; // Initialize counter
while($row = $news->fetch_assoc()):
// Format date_published to display only the date part (YYYY-MM-DD)
$date_published = date('F j, Y', strtotime($row['date_published']));
$trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
unset($trans["\""], $trans["<"], $trans[">"], $trans["<h2"]);
$desc = strtr(html_entity_decode($row['content']), $trans);
$desc = str_replace(array("<li>", "</li>"), array("", ", "), $desc);
// Determine the class based on the position
$div_class = ($count % 2 == 0) ? 'col-6' : 'col-6 mt-4';
?>
<div class="<?php echo $div_class; ?>">
<a href="./index.php?page=read_news&c=<?php echo md5($row['id']) ?>" data-id = '<?php echo $row['id'] ?>'><img src="assets/uploads/content_images/<?php echo $row['cover_img'] ?>" alt="" class="img-fluid mb-4 canva-img"></a>
</div>
<?php
$count++;
// Open a new row every two items
if ($count % 2 == 0) {
if ($count > 0) {
echo '</div></div>'; // Close previous row
}
echo '<div class="col-lg-6"><div class="row">'; // Open new row
}
endwhile;
// Close the last row if it was not closed
if ($count % 2 != 0) {
echo '';
}
endif;
?>
</div></div>