Log in

View Full Version : Display blogs in mulitple columns.



har30
10-11-2015, 12:11 PM
Below is a code which gets blogs from database and displays it in single column on screen, I want to display blogs in multiple columns may be three,with each column displaying 10 blogs ordered by their id, so how to do that. If it is too long to answer here maybe mentioning any method that is easy to use can help me.

this is how I call posts from db:


$query = ("SELECT blogs_id, title, body, posted_by, category FROM blogs INNER JOIN
categories ON categories.category_id=blogs.category_id ORDER BY blogs_id desc LIMIT 10");
foreach($db->query($query)as $row){
$blogs_id = $row['blogs_id'];
$title = $row['title'];
$body = $row['body'];
$posted_by = $row['posted_by'];
}

$get_user = $db->prepare("SELECT * FROM userss WHERE username= :username");
$get_user->execute(array(':username'=>$posted_by));
$get_row = $get_user->fetch(PDO::FETCH_ASSOC);

$profilephoto = $get_row['profile_photo'];
if ($profilephoto_ == "") {
$profilephoto = "./img/avatar_pic.png";
}
else {
$profilephoto = "./userdata/profile_photos/".$profilephoto_info;
}

echo "<h2>$title</h2>
<p>$body</p>
<img src='$profilephoto' height='60'><br />
By:<a href='$posted_by'>$full_name</a>";