Fetch info in bootstrap card [duplicate] - php

This question already has answers here:
Bootstrap 3 - style a site with 3 columns per row on medium & large devices and two columns on small
(2 answers)
Closed 2 years ago.
I am trying to display cards but in this way, all three cards are showing the same information whereas I want every card to show specific entries in the database like 1st one the first entry and second one the second then the third one the third then change line and restart to display 4,5,6 entry and so on. Can anyone please help?
include_once('db/connection.php');
$query="select * from news ORDER BY id DESC";
$result=mysqli_query($conn,$query);
?>
<?php
while($rows=mysqli_fetch_array($result))
{
$cc =$rows['category2'];
?>
<div>
<div class="container">
<div class="cust_bloglistintro">
<div class="row">
<div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
<div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100 d-block" src="images/<?php echo $rows['thumbnail'];?>">
<div class="card-body">
<h4 class="card-title"><?php echo $rows['title']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
<p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
</div>
<div class="text-center" style="bottom: 10px;"><i class="fab fa-whatsapp-square" id="whatsapp"></i><i class="fab fa-facebook-square" id="facebook"></i><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></div>
</div>
</div>
<div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
<div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100 d-block" src="images/<?php echo $rows['thumbnail'];?>">
<div class="card-body">
<h4 class="card-title"><?php echo $rows['title']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
<p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
</div>
<div class="text-center" style="bottom: 10px;"><i class="fab fa-whatsapp-square" id="whatsapp"></i><i class="fab fa-facebook-square" id="facebook"></i><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></div>
</div>
</div>
<div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
<div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100 d-block" src="images/<?php echo $rows['5'];?>">
<div class="card-body">
<h4 class="card-title"><?php echo $rows['1']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
<p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
</div>
<div class="text-center" style="bottom: 10px;"><i class="fab fa-whatsapp-square" id="whatsapp"></i><i class="fab fa-facebook-square" id="facebook"></i><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>

Many ways of doing this, but I've used this approach recently...
<?php
$resultCount=0;
if(mysqli_num_rows($result) >0)
{
?>
<div>
<div class="container">
<div class="cust_bloglistintro">
<div class="row">
<?php
while($rows=mysqli_fetch_array($result))
{
$cc =$rows['category2'];
?>
<div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
<div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100 d-block" src="images/<?php echo $rows['thumbnail'];?>">
<div class="card-body">
<h4 class="card-title"><?php echo $rows['title']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
<p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
</div>
<div class="text-center" style="bottom: 10px;"><i class="fab fa-whatsapp-square" id="whatsapp"></i><i class="fab fa-facebook-square" id="facebook"></i><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></div>
</div>
</div>
<?php
$resultCount++;
if ($resultCount % 3 == 0) // start new row
{
?>
</div>
<div class="row">
<?php
}
}
if ($resultCount % 3 != 0) // if we didn't just end a row in the loop, end it now
{
?>
</div>
<?php
}
// now close divs
?>
</div>
</div>
</div>
<?php
} // end of if num_rows>0
?>

Related

not getting a diffrent price getting a same price for every pic not getting different id on caption

<div id="products" class="row list-group">
<?php $counter = 1; foreach ($photo_products as $value) {
$product = new WC_Product( $value->ID ); ?>
<div class="item col-xs-4 col-lg-4">
<div class="thumbnail">
<img class="myImg" class="group list-group-image" src="<?php echo get_the_post_thumbnail_url($value->ID, array(324, 324)); ?>" alt="" />
<div class="caption">
<h4 class="group inner list-group-item-heading">
<?php echo esc_attr($product->get_title()); ?></h4>
<div class="row">
<div class="col-xs-12 col-md-6">
<p class="lead">
<?php echo wc_price($product->get_price()); ?></p>
</div>
<div class="col-xs-12 col-md-6">
<a class="btn btn-success " href="<?php echo esc_attr($current_url).'/?add-to-cart='.esc_attr($value->ID); ?>">
<?php esc_html_e('Add to cart', 'woocommerce-photography-plugin'); ?>
</a>
</div>
</div>
</div>
<div id="myModal" class="modal">
<span class="close">×</span>
<img id="img01" class="modal-content" src="">
<div id="caption" class="modal-content">
<h4 class="group inner list-group-item-heading">
<?php echo esc_attr($product->get_title()); ?></h4>
<div class="row">
<div class="col-xs-12 col-md-6">
<p class="lead" >
<?php echo wc_price($product->get_price()); ?></p>
</div>
<div class="col-xs-12 col-md-6">
<a class="btn btn-success " href="<?php echo esc_attr($current_url).'/?add-to-cart='.esc_attr($value->ID); ?>">
<?php esc_html_e('Add to cart', 'woocommerce-photography-plugin'); ?>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php $counter++; } ?>
</div>
Instead of
$product = new WC_Product( $value->ID );
You can try, following code:
$product = WC_Product::find()->where('id'=>$value->ID);

how to display 3 columns dynamic data from database using bootstrap 4

Following is my code I am displaying details as 3 columns per row using Bootstrap class row.
I tried like changing div and some condition
<div class="container">
<?php
if($lclResult->rowCount() > 0){
while($row = $lclResult->fetch(PDO::FETCH_ASSOC)) {
# code...
$lclUserName = $row['us_business_name'];
$lclImage1 = $row['us_image1'];
$lclCategory = $row['us_category'];
$lclArea = $row['us_area'];
?>
<div class="row">
<div class="col-sm-4">
<div class="card">
<img class="card-img-top " src="<?php echo $lclImage1 ?>" alt="Card image" style="width:100%; height: 158px;">
<div class="card-body">
<h4 class="card-title"><?php echo $lclUserName?></h4>
<p class="card-text" style="font-size: 25px;"><?php echo $lclCategory?></p>
<hr>
<i class="fa fa-map-marker" style="font-size: 23px;"><span> </span><?php echo $lclArea?></i>
<!-- See Profile -->
</div>
</div>
<?php
}
?>
</div>
<?php
} else {
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1> NO RESULT FOUND...</h1>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
I want to display 3 columns per row to display data. If anyone knows Please guide me with the above code.
Change your code like this
<div class="container">
<div class="row">
<?php
if($lclResult->rowCount() > 0){
while($row = $lclResult->fetch(PDO::FETCH_ASSOC)) {
# code...
$lclUserName = $row['us_business_name'];
$lclImage1 = $row['us_image1'];
$lclCategory = $row['us_category'];
$lclArea = $row['us_area'];
?>
<div class="col-sm-4">
<div class="card">
<img class="card-img-top " src="<?php echo $lclImage1 ?>" alt="Card image" style="width:100%; height: 158px;">
<div class="card-body">
<h4 class="card-title">
<?php echo $lclUserName?>
</h4>
<p class="card-text" style="font-size: 25px;">
<?php echo $lclCategory?>
</p>
<hr>
<i class="fa fa-map-marker" style="font-size: 23px;">
<span>
</span>
<?php echo $lclArea?>
</i>
<!-- See Profile -->
</div>
</div>
</div>
<?php
}
?>
<?php
} else {
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1> NO RESULT FOUND...
</h1>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>

Bootstrap, why are products displayed arbitrarily?

Have a website in three languages. The porducts select from a mysql database and showed wiht a do-while-loop.
<!-- Shop Page Area Start-->
<div class="shoppage-area">
<div class="container">
<div class="about-desc">
<h2>
<?php echo $page['subtitle']; ?>
</h2>
<?php echo $page['content']; ?>
</div>
<div class="row">
<?php
do {
?>
<!--Product Start-->
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="sngle-product">
<div class="product-thumb">
<img src="<?php echo $product['img']; ?>" alt=""/>
<h2>
<a href="#">
<?php echo $product['name']; ?>
</a>
</h2>
</div>
<h3>
<?php echo $product['desc']; ?>
</h3>
<span><?php echo $product['size']; ?></span> <span class="price"><?php echo $product['price']; ?> LE</span>
<div class="product-overlay">
<ul>
<li>
<div class="product-quantity">
<div class="input-number">
<input type="text" value="1" name="quantity">
</div>
</div>
</li>
<li><a class="orderbtn" href="#" data-uid="<?php echo $product['uniqueid']; ?>">ORDER</a></li>
</ul>
</div>
</div>
</div>
<!-- Product End -->
<?php
} while ($product = $res->fetch_assoc()) ?>
</div>
<!-- end Row -->
</div>
</div>
The problem is that in one language showed correctly and in the other i get a lot spaces between the products. See the image
enter image description here
How i can solve this
Add an additional class flex-row to the product wrapping row element. And try applying the following styles.
.flex-row{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
You can divide your column like this
<div class="shoppage-area">
<div class="container">
<div class="about-desc">
</div>
<div class="row">
<?php $i=1;
do {
?>
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="sngle-product">
<div class="product-thumb">
<img src="<?php echo "test"; ?>" alt=""/>
<h2><?php echo "test"; ?> </h2>
</div>
<h3><?php echo ($i==2)? " testtesttesttesttesttest testtesttesttest test": "test"; ?></h3>
<span><?php echo "test"; ?></span> <span class="price"><?php echo 12321; ?> LE</span>
<div class="product-overlay">
<ul>
<li>
<div class="product-quantity">
<div class="input-number">
<input type="text" value="1" name="quantity">
</div>
</div>
</li>
<li><a class="orderbtn" href="#" data-uid="<?php echo "1231"; ?>">ORDER</a></li>
</ul>
</div>
</div>
</div>
<?php
echo $i%4;
if($i%4== 0 && $i > 1) {
echo '</div><div class="row">';
}
$i++;
} while ($i<=10) ?>
</div>
</div>
</div>

Adding active class in Bootstrap Collapse

How to set a panel as active by default on the first load, The code below shows as the dynamic page show help me to solve the issue:
<div class="panel-group collapse-style-1" id="accordion">
<?php foreach ($careers['result'] as $resclients){?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne<?php echo $conn->stripval($resclients['career_id']);?>" aria-expanded="true" class="collapsed">
<i class="fa fa-life-ring pr-10"></i><?php echo $conn->stripval($resclients['job_title']);?> - <?php echo $conn->stripval($resclients['experience']);?>
</a>
</h4>
</div><br>
<div id="collapseOne<?php echo $conn->stripval($resclients['career_id']);?>" class="panel-collapse collapse" aria-expanded="true" style="height: 0px;">
<div class="panel-body">
<?php echo $conn->stripval($resclients['job_desc']);?>
</div>
</div>
</div>
<?php } ?>
</div>
try this,
<div class="panel-group collapse-style-1" id="accordion">
<?php $i=1; foreach ($careers['result'] as $resclients){?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne<?php echo $conn->stripval($resclients['career_id']);?>" aria-expanded="<?=($i==1)?'true':'false';?>" class="<?=($i==1)?'collapsed':'';?>">
<i class="fa fa-life-ring pr-10"></i><?php echo $conn->stripval($resclients['job_title']);?> - <?php echo $conn->stripval($resclients['experience']);?>
</a>
</h4>
</div><br>
<div id="collapseOne<?php echo $conn->stripval($resclients['career_id']);?>" class="panel-collapse collapse <?=($i==1)?'in':'';?>" aria-expanded="<?=($i==1)?'true':'false';?>" style="height: 0px;">
<div class="panel-body">
<?php echo $conn->stripval($resclients['job_desc']);?>
</div>
</div>
</div>
<?php $i++; } ?>
</div>
I tried myself now it is working fine thank you for giving a idea to solve the problem
<div class="panel-group collapse-style-1" id="accordion">
<?php $c=0; foreach ($careers['result'] as $resclients){ $c++;?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne<?php echo $conn->stripval($resclients['career_id']);?>" aria-expanded="<?php if($c==1){ echo "true"; }else{ echo "false"; } ?>" class="<?php if($c==1){ echo ""; }else{ echo "collapsed"; } ?>">
<i class="fa fa-life-ring pr-10"></i><?php echo $conn->stripval($resclients['job_title']);?> - <?php echo $conn->stripval($resclients['experience']);?>
</a>
</h4>
</div><br>
<div id="collapseOne<?php echo $conn->stripval($resclients['career_id']);?>" class="panel-collapse collapse <?php if($c==1){ echo "in"; }else{ echo ""; } ?>" aria-expanded="<?php if($c==1){ echo "true"; }else{ echo "false"; } ?>" style="<?php if($c==1){ echo "true"; }else{ echo "height: 0px;"; } ?>">
<div class="panel-body">
<?php echo $conn->stripval($resclients['job_desc']);?>
</div>
</div>
</div>
<?php } ?>
</div>

Dynamic bootstrap tabs using php and mysql

I have Bootstrap modal tabs and it is works fine without data loop. I am trying to fill tabs using data from db(fetch), but it is not working when i am changing tabs, how can call my required tab data on press to my tab? I know that I have problem with looping or maybe "active"- class of tabs. Here is my code. What is wrong?
<div class="row">
<div class="col">
<div class="row">
<div class="col-sm-4">
<h4 class="mb-4">Ölkələr</h4>
</div>
</div>
<div class="row">
<?php
$conn = connect_to_bd();
mysqli_set_charset($conn,"utf8");
$selectolke = mysqli_query($conn, "Select t.ID as tid,t.text_az as textaz, c.textid as textid, c.olkeflag as olkeflag, c.id as cid, c.country_az as country_az from countries c, text t where t.id = c.textid");
while($selectolkerow = mysqli_fetch_array($selectolke))
{
$textid = $selectolkerow["textid"];
$country_az = $selectolkerow["country_az"];
$olkeflag = $selectolkerow["olkeflag"];
$olkeid = $selectolkerow["cid"];
?>
<div class="col-lg-4">
<div class="tabs tabs-vertical tabs-left tabs-navigation">
<ul class="nav nav-tabs col-sm-3">
<li class="nav-item active">
<a class="nav-link" href="#tabsNavigation<?php echo $textid; ?>" data-toggle="tab"><img src="lib/png/<?php echo $olkeflag; ?>.png"> <?php echo $country_az; ?></a>
</li>
</ul>
</div>
</div>
<div class="col-lg-8">
<div class="tab-pane tab-pane-navigation active" id="tabsNavigation<?php echo $textid; ?>">
<h4><?php echo header_subname_olke_select_az($olkeid); ?></h4>
<p class="notworkingcss" style="color: #fff;font-family:Verdana, sans-serifsans-serif;text-shadow: black 1px 1px 2px;font-size: 1.2em;">
<?php echo text_olke_select_az($textid, $olkeid); ?>
</p>
<div class="row portfolio-list lightbox m-0" data-plugin-options="{'delegate': 'a.lightbox-portfolio', 'type': 'image', 'gallery': {'enabled': true}}">
<div class="col-12 col-sm-6 col-lg-3">
<div class="portfolio-item">
<span class="thumb-info thumb-info-lighten thumb-info-centered-icons">
<span class="thumb-info-wrapper">
<img src="img/products/yerli/1.jpg" class="img-fluid" alt="Et mehsullari">
<span class="thumb-info-action">
<a href="img/products/yerli/1.jpg" class="lightbox-portfolio">
<span class="thumb-info-action-icon thumb-info-action-icon-light"><i class="fa fa-search-plus"></i></span>
</a>
</span>
</span>
</span>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3">
<div class="portfolio-item">
<span class="thumb-info thumb-info-lighten thumb-info-centered-icons">
<span class="thumb-info-wrapper">
<img src="img/products/yerli/2.jpg" class="img-fluid" alt="Et mehsullari">
<span class="thumb-info-action">
<a href="img/products/yerli/2.jpg" class="lightbox-portfolio">
<span class="thumb-info-action-icon thumb-info-action-icon-light"><i class="fa fa-search-plus"></i></span>
</a>
</span>
</span>
</span>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3">
<div class="portfolio-item">
<span class="thumb-info thumb-info-lighten thumb-info-centered-icons">
<span class="thumb-info-wrapper">
<img src="img/products/yerli/3.jpg" class="img-fluid" alt="Et mehsullari">
<span class="thumb-info-action">
<a href="img/products/yerli/3.jpg" class="lightbox-portfolio">
<span class="thumb-info-action-icon thumb-info-action-icon-light"><i class="fa fa-search-plus"></i></span>
</a>
</span>
</span>
</span>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>

Categories