Why my bootstrap cards R showing in single column when I am trying to show 3 column?

I am new to PHP- Mysql and bootstrap. I am trying to display records using bootstrap 4.1 cards class. I am trying to show 3 cards in each row but it shows only in one column. I have searched for my error but could not detect. Can anyone help me on this please? connection to database is working fine and I have tried both PDO and mysqli method.
here is the code for the container. and thank you for your special time spending for me.

<div class="container">

  <div class="row" style="margin-top: 4%">

    <!--  Entries Column -->
    <div class="col-md-8">
			
      <!-- data Post -->
<?php 
 if (isset($_GET['pageno'])) {
        $pageno = $_GET['pageno'];
    } else {
        $pageno = 1;
    }
    $no_of_records_per_page = 8;
    $offset = ($pageno-1) * $no_of_records_per_page;


    $total_pages_sql = "SELECT COUNT(*) FROM tblposts";
    $result = mysqli_query($con,$total_pages_sql);
    $total_rows = mysqli_fetch_array($result)[0];
    $total_pages = ceil($total_rows / $no_of_records_per_page);

			
		$stmt = $DB_con->prepare("select tblposts.id as pid,tblposts.PostTitle as posttitle,tblposts.PostImage,tblcategory.CategoryName as category,tblcategory.id as cid,tblsubcategory.Subcategory as subcategory,tblposts.PostDetails as postdetails,tblposts.PostingDate as postingdate,tblposts.PostUrl as url from tblposts left join tblcategory on tblcategory.id=tblposts.CategoryId left join  tblsubcategory on  tblsubcategory.SubCategoryId=tblposts.SubCategoryId where tblposts.Is_Active=1 order by tblposts.id desc  LIMIT {$offset}, {$no_of_records_per_page}");	
$stmt->execute();


	
			if($stmt->rowCount() > 0)
		//$stmt = $stmt->fetchall(PDO::FETCH_ASSOC);
		
	{
		while($row=$stmt->fetch(PDO::FETCH_ASSOC))
		{
			extract($row);
			?>
			


			<div class="col-lg-4 col-md-6"> 
      <div class="card mb-4"> 
 <img class="card-img-top" src="admin/postimages/<?php echo htmlentities($row['PostImage']);?>" alt="<?php echo htmlentities($row['posttitle']);?>">
        <div class="card-body">
          <h5 class="card-title"><?php echo htmlentities($row['posttitle']);?></h5>
             <p><b>Category : </b> <a href="category.php?catid=<?php echo htmlentities($row['cid'])?>"><?php echo htmlentities($row['category']);?></a> </p>
   
          <a href="news-details.php?nid=<?php echo htmlentities($row['pid'])?>" class="btn btn-primary">Read More &rarr;</a>
        </div>
        <div class="card-footer text-muted">
          Posted on <?php echo htmlentities($row['postingdate']);?>
       
        </div>
      </div>
			
						
			</div> 	
			
<?php } }?>
   
		 
		

      <!-- Pagination -->


<ul class="pagination justify-content-center mb-4">
    <li class="page-item"><a href="?pageno=1"  class="page-link">First</a></li>
    <li class="<?php if($pageno <= 1){ echo 'disabled'; } ?> page-item">
        <a href="<?php if($pageno <= 1){ echo '#'; } else { echo "?pageno=".($pageno - 1); } ?>" class="page-link">Prev</a>
    </li>
    <li class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?> page-item">
        <a href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?pageno=".($pageno + 1); } ?> " class="page-link">Next</a>
    </li>
    <li class="page-item"><a href="?pageno=<?php echo $total_pages; ?>" class="page-link">Last</a></li>
</ul>

    </div>

    <!-- Sidebar Widgets Column -->
  <?php include('includes/sidebar.php');?>
			
  </div>
  <!-- /.row -->

</div>

You currently have a non-workable mixture of mysqli and PDO statements, that are probably producing php errors.

Do this -

  1. Use the php PDO extension.
  2. Move all the get pageno and the database specific code above the start of the html document.
  3. Both of the database queries must have the same tables, joins, and where clauses. You should build this common part of the queries in a php variable then use this variable in both of the queries.
  4. Fetch the data from the second query into an appropriately named php variable. This variable will be used as the input to the html document. This will let you use var_dump()/print_r() on the data to make sure it is what you expect.
  5. The $total_pages calculation should be used to either validate or limit the $pageno value. There’s no point in executing a query where the requested pageno is greater than the total number of pages.
  6. Since the two values being used in the LIMIT x,y clause are produced solely within the php code, there’s no need to use a prepared query, which you aren’t actually doing correctly now.
  7. Don’t use extract(), which you aren’t actually using the result of.
  8. If you set the default PDO fetch mode to assoc when you make the database connection, you won’t have specify it in every fetch statement.

Once you do these things it will simplify and clean up your code and it will be easy to determine if the problem is the query/data or in the html markup. As it stands, I don’t think anyone here has a chance at figuring out what’s wrong.

1 Like

Thank you for your support. I have no problem with data reading. I checked on both PDO and Mysqli method. I will make sure only one method will be in place.

I have found problem with bootstrap col-md declaration and solved partially.

Thank you again sir.

Sponsor our Newsletter | Privacy Policy | Terms of Service