I need to display cards horizontally from my database using PHP
My code is below
function getHighlights($conn){0
$q = "SELECT *, MONTHNAME(date) AS themonth, DAYOFMONTH(date) AS theday, YEAR(date) AS theyear FROM highlights ORDER BY date DESC LIMIT 0,3";
$r = mysqli_query($conn, $q);
while($page = mysqli_fetch_assoc($r)){
echo '
<div class="container">
<div class="row-fluid">
<div class="card-deck mt-5 mb-4">
<div class="card col-md-6 col-lg-4 col-xs-12">
<img src="../thadd/images/'.$page['image'].'" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">'.$page['title'].'</h5>
<p class="card-text mb-5">'.$page['message'].'</p>
<div class="text-center mb-3">
Read More →
</div>
<div class="card-footer text-muted">
Posted on Tuesday by '.$page['author'].'
</div>
</div>
</div>
</div>
</div>
</div>
';
}
Generally, move the row out of the loop as shown in the following pseudo code.
<div class="container">
<div class="row">
-- WHILE LOOP --
<div class="col">
-- OUTPUT DATA --
</div> <!-- col -->
-- END WHILE --
</div><!-- row -->
</div> <!-- container -->
Read the bootstrap grid
https://getbootstrap.com/docs/4.3/layout/grid/
Related
I am trying to create categories nav-pill with bootstrap 5.
İt has two cols first one is futured post and second one displays 5 posts.
I have tried like this but it wasn't right because they are in different columns (side by side), simple example:
$sql = "SELECT * FROM articles WHERE article_id = ? ORDER BY article_id DESC";
$result = $pdo->prepare($sql);
$result->execute([$cats['cat_id']]);
if ($result->rowCount() > 0) {
$array = array('class 1', 'class 2');
$i=0;
while($row = $result->fetch()) { ?>
<div class="<?php $array[$i];?>">
</div>
<?php
$i++;
}
}
?>
My html:
<div class="row">
<!-- first futured column ->
<div class="col-sm-6">
<div class="whats-news-single mb-40 mb-40">
<div class="whates-img">
<img src="..." alt="">
</div>
<div class="whates-caption">
Secretart for Economic Air plane that looks like
<p>Struggling to sell one the market won’t stop actress and the and singer Jennifer Lopez.</p>
<span class="small">by Alice cloe - Jun 19, 2020</span>
</div>
</div>
</div>
<!-- second column displays 5 articles ->
<div class="col-sm-6">
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>The pros and cons of business agency</h6>
<div class="small mt-1">May 17, 2021</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>5 reasons why you shouldn't startup</h6>
<div class="small mt-1">Apr 04, 2021</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>Ten questions you should answer truthfully.</h6>
<div class="small mt-1">Jun 30, 2021</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>Five unbelievable facts about money.</h6>
<div class="small mt-1">Nov 29, 2021</div>
</div>
</div>
</div>
</div>
</div>
This is how it has to look like
enter image description here
I'm a bit confused by your question. Is the featured Post a randomly selected post, or is it always the newest in the database? If its always the newest, you could just query by article_id desc (as you're currently doing) and then access the first post via:
$array[0]
That way you can now create your featured post view by using all the data available in the first index of your array.This only works if you put your query results into an array, as described here:. Note that you should use mysqli functions, and not mysql. For the next five, you can then make use of for to display five more articles:
for($i = 1; $i <= 5;$i++) {
// repeat the section for one post five times
}
This will allow you to create the view you described.
I have problem in listing the products 3 in a row the line get broken at the 4th
when it's at the 4th item it's listing them like
1. row 1 1 1
2. row 0 0 1
3. row 1 0 0
4. row 1 1 1
5. row 0 0 1
I can't find where is the problem.
I checked the bootstrap container structure. It's says the first col after the row is the left the second is the center and the third is the right.
I made 3 col in a row but that didn't work i can't use the left side it's like the container has only center and right side. So the size of the items not fitting the container thats why it's skipping as i find when i make the item size <div class="col-md-2"> the items get in the line correct but they become smaller. I need them <div class="col-md-3"> everything get broken when it's become 3 or 4
<?php
include "header.php";
$id=isset($_GET['kategori_id']) ? $_GET['kategori_id']:"";
$kitap_cek_miktar = 12;
$sql=$db->prepare("SELECT COUNT(*) AS kayit_sayisi FROM kitap_bilgi where kategori_id=$id ");
$sql->execute();
$kayit_say=$sql->fetch(PDO::FETCH_ASSOC);
$kayit_sayisi = $kayit_say['kayit_sayisi'];
$sayfa_sayisi=ceil($kayit_sayisi/$kitap_cek_miktar);
if (!isset($_GET['sayfa'])) {
$sayfa=1;
}else{
$sayfa=$_GET['sayfa'];
}
$ilk_kayit=($sayfa-1)*$kitap_cek_miktar;
$resim=$db->prepare("SELECT kitap_ad,kitap_resim, kitap_fiyat,kitap_id from kitap_bilgi where kategori_id=$id LIMIT ".$ilk_kayit.",".$kitap_cek_miktar);
$resim->execute();
$veri = $resim->fetchAll(PDO::FETCH_ASSOC); // tablo verilerini oku
?>
<div class="container">
<!--- this stucture is like a banner for an e-commerce website --->
<div class="row">
<div class="col-md-12">
<div class="page-title-wrap">
<div class="page-title-inner">
<div class="row">
<div class="col-md-4">
<div class="bread">Home › Category</div>
<div class="bigtitle">Category</div>
</div>
<div class="col-md-3 col-md-offset-5">
<button class="btn btn-default btn-red btn-lg">Purchase Theme</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--->
<div class="row">
<div class="col-md-9"><!--Main content-->
<div class="title-bg"> <!--- this stucture is to change the list way an e-commerce website --->
<div class="title">Category - All products</div>
<div class="title-nav">
<i class="fa fa-th-large"></i>grid
<i class="fa fa-bars"></i>List
</div>
</div> <!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--->
<div class="row prdct"><!--Products listing the products pic, price, name -->
<?php foreach($veri as $kayit): ?>
<div class="col-md-4"> <!-- items list size -->
<div class="productwrap">
<div class="pr-img">
<a href="urun_detay.php?kitap_id=<?= $kayit['kitap_id']?>">
<img src="images/<?= $kayit['kitap_resim']?>" alt="<?= $kayit['kitap_ad']?>" class="img-responsive">
</a>
<div class="pricetag">
<div class="inner"><?= $kayit['kitap_fiyat'].'₺'?></div>
</div>
</div>
<span class="smalltitle">
<?= $kayit['kitap_ad'].$kayit['kitap_id']?>
</span>
</div>
</div>
<?php endforeach; ?>
</div><!--Products ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--->
<ul class="pagination shop-pag"><!--pagination making the pages 1.2.3 next -->
<?php for ($sayfa=1;$sayfa<=$sayfa_sayisi;$sayfa++)
{
echo '<li>
' . $sayfa . '
</li> ';
} ?>
</ul><!--pagination--><!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--->
</div><!--Main content-->
<div class="col-md-3"><!--sidebar listing the categories -->
<div class="title-bg">
<div class="title">Categories</div>
</div>
<div class="categorybox">
<?php categories();?>
</div>
</div><!--sidebar-->
</div>
</div>
<?php
include('footer.php');
?>
Im trying to add a group onto some bootstrap cards so that a the cards are displaying the data first and then the relevant cards after, e.g:
22 March 2018
1st-Card 2nd-Card
23 March 2018
1st-Card
At the moment I have this, but this displays all of my cards on a row:
<div class="card">
<div class="card-body">
<div class="card-header"><i class="material-icons floatleft">today</i><div floatleft>'.date("d/m/Y", strtotime($row['Date'])).'</div></div>
<h5 class="card-title">'.$row['Firstname'].' '.$row['Surname'].'</h5>
<p class="card-text">'.$row['Notes'].'</p>
</div>
<div class="card-footer">
<small class="text-muted">Added: '.date("d/m/Y", strtotime($row['timestamp'])).'</small>
</div>
</div>
</div>
Is their anyway to group by date?
This is my PHP for each row:
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($tablequery))
{
$amount = $row['LineRef'] == 0 ? '' :
number_format($row['LineRef']);
echo
' <div class="col-sm-3 OMHCardPadding">
<div class="card">
<div class="card-body">
<div class="card-header"><i class="material-icons floatleft">today</i>
<div floatleft>'.date("d/m/Y", strtotime($row['Date'])).'</div></div>
<h5 class="card-title OMHCardPadding">'.$row['Firstname'].' '.$row['Surname'].'</h5>
<p class="card-text OMHCardPadding">'.$row['Notes'].'</p> </div> <div class="card-footer">
<small class="text-muted">Added: '.date("d/m/Y",strtotime($row['timestamp'])).'</small>
</div>
</div>
</div>
';
$total += $row['LineRef'];
$no++;
}?>
My actual query is just a simple SELECT statement:
SELECT * FROM APPOINTMENTS
I want the information tag to be at the right side of the web page. Rest of the things are in the middle of the page. While I am not able to move the information to the right side. Also, because of it the footer disappeared. While I remove the information code, the footer works. Please help me right-align the information widget and also have the footer too.
<div class="container">
<div class="card border-light mb-3 text-center">
<p class="card-header">Videos</p>
</div>
<div id="userSuccess" class="hide" role="alert">
<div id="successUserContent"></div>
</div>
<div class="row" id="userVid">
<?php
$allVid = Schema::getAll();
for ($i = 0; $i < count($allVid); $i++) {
echo <<<HTML
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<div class="card-body">
<img class="card-img-top" src="http://placehold.it/700x400" alt="">
<h4 class="card-title">{$allVid[$i]->getTitle()} </h4>
</div>
</div>
</div>
HTML;
}
?>
</div>
<div class="row">
<div class="col-md-4 order-md-2 mb-4">
<div class="card my-4">
<h5 class="card-header">Information</h5>
<div class="card-body">
<div class="row">
<ul class="list-unstyled mb-0">
<li>
...
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
require_once './page/footer.php';
?>
For right align, you'll want to add the class of "justify-content-end" after your "row" class.
<div class="row justify-content-end"><!-- ADDED HERE-->
<div class="col-md-4 order-md-2 mb-4">
<div class="card my-4">
<h5 class="card-header">Information</h5>
<!-- REST OF YOUR CODE-->
For your footer, you'll need to wrap your URL in parenthesis.
<?php require_once('/yourdirectory/yourfooter.php'); ?>
My program is fetching 3 customer records from database in PHP language.i want to show the return result from database in a bootstrap
grid view like 3 col of col-sm-4 in one row. Right now, it shows all
the result in one vertical line.Next thing i want is if have more
records, then the next record should show in next line and allow only
3 records in one line every time i fetch records from database.
Looking for the solution.
<div class="container-fluid" style="margin:0px auto;height:auto;border:1px solid yellow;">
#foreach($reviews as $review)
<div class="row">
<div class="col-sm-12">
<div class="col-sm-4">
<div>name is:- {{$review->name}}</div>
<div>course is:-{{$review->course}}</div>
<div>designation is:-{{$review->designation}}</div>
<div>company is:-{{$review->company}}</div>
<div>comments:-{{$review->comments}} </div>
<div>status:{{$review->status}} </div>
<div>priority:{{$review->priority}}</div>
<div>review date:-{{$review->review_date}}</div>
<?php
$image =stripslashes($review->image);
?>
<div>images:<img src='{{asset("$image")}}'></div>
</div>
</div>
</div>
#endforeach
</div>
You could do something like this
<div class="row">
<div class="col-sm-4">data 1</div>
<div class="col-sm-4">data 2</div>
<div class="col-sm-4">data 3</div>
<div class="col-sm-4">data 4</div>
<div class="col-sm-4">data 5</div>
<div class="col-sm-4">data 6</div>
.
.
.
.
.
</div>
This will add 3 columns in each row for N number of data automatically!
Move the row outside of the loop as shown below
Also, I'm not sure why you have a col-sm-12 and a col-sm-4? I'm sure that will confuse things
<div class="row">
#foreach($reviews as $review)
<!--<div class="col-sm-12"> -->
<div class="col-sm-4">
<div>name is:- {{$review->name}}</div>
<div>course is:-{{$review->course}}</div>
<div>designation is:-{{$review->designation}}</div>
<div>company is:-{{$review->company}}</div>
<div>comments:-{{$review->comments}} </div>
<div>status:{{$review->status}} </div>
<div>priority:{{$review->priority}}</div>
<div>review date:-{{$review->review_date}}</div>
<?php
$image =stripslashes($review->image);
?>
<div>images:<img src='{{asset("$image")}}'></div>
</div>
<!-- </div> -->
#endforeach
</div>