Jump to content
williamh69

display grid from mysqli and php

Recommended Posts

hi trying to make a grid of two columns , data from db using mysqli and php, but it does not work...can you guys help me thanks in advance

<?php
$limit=2;
$count=0;

echo"<table  border='0' align='center' cellpadding='2' cellspacing='2' width='70%'>";

$query = "SELECT * FROM posts";
                       $select_all_categories_query = mysqli_query($connection, $query);

                       while ($row = mysqli_fetch_assoc($select_all_categories_query)){
                       
                       $post_image = $row['post_image'];
                       $post_title = $row['post_title'];
                       $post_content = $row['post_content'];
                       $post_user = $row['post_user'];
                       $post_date = $row['post_date'];

                       
                       if ($count < $limit) {

         if($count ==0) {

         echo"<tr>";

         }

echo"<div class='post-img'>";
echo"<div class='img'>";
echo"<img src='assets/img/blog/$post_image' alt='Blog'>";
echo"</div>";
echo"<div class='tag'>";
echo"<a href='#'><span class='icon'><i class='fas fa-tags'></i></span> Business</a>";
echo"</div>";
echo"</div>";
echo"<div class='cont'>";
echo"<h6><a href='blog-single.html'>$post_title</a></h6>";
echo"<p>$post_content</p>";
echo"<div class='info'>";
echo"<a href='#'><span class='author'><img src='assets/img/blog/4.png' alt='Post'></span>$post_user</a>";
echo"<a href='#' class='right'><span class='icon'><i class='fas fa-clock'></i></span> $post_date</a>";
echo"</div>";
echo"</div>";

}else {

$count=0;

echo"<div class='post-img'>";
echo"<div class='img'>";
echo"<img src='assets/img/blog/$post_image' alt='Blog'>";
echo"</div>";
echo"<div class='tag'>";
echo"<a href='#'><span class='icon'><i class='fas fa-tags'></i></span> Business</a>";
echo"</div>";
echo"</div>";
echo"<div class='cont'>";
echo"<h6><a href='blog-single.html'>$post_title</a></h6>";
echo"<p>$post_content</p>";
echo"<div class='info'>";
echo"<a href='#'><span class='author'><img src='assets/img/blog/4.png' alt='Post'></span>$post_user</a>";
echo"<a href='#' class='right'><span class='icon'><i class='fas fa-clock'></i></span> $post_date</a>";
echo"</div>";
echo"</div>";

}

$count++;

}

echo"</tr></table>";

?>

 

this is the result

OnPaste.20191110-215034.png.b3062a8bdf1e9722a9fde5c0beacb0c9.png

 

i want this kind of result

OnPaste.20191110-215329.png.df9bc64588c58221e90ae714d026bbf8.png

thank you

Share this post


Link to post
Share on other sites

Note that HTML table tags (e.g. <table>, <tr>, <td>) should be reserved for tabular data. Perhaps one of the solutions found here will help:
https://css-tricks.com/fluid-width-equal-height-columns/

You could also consider using CSS grids:
https://css-tricks.com/snippets/css/complete-guide-grid/

Just be aware that browser support isn't exactly ideal for CSS grids. More information can be found here:
https://caniuse.com/#feat=css-grid

Share this post


Link to post
Share on other sites

 

 

@williamh69 Next time you make a table remember to use <td> not <div> and You need a <tr> in there

	    if($count ==0) {
	         echo"<tr>";
	         }
	

should have been just echo "<tr> No if.

and

<table  border='0' align='center' cellpadding='2' cellspacing='2' width='70%'>

Is totally out of date and  wrong.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.