Hi I am new in PHP but I want to Sum my amount and display it on the page currently I am doing like this but it is not showing.
<div class="col-md-4 col-lg-4">
<div class="panel panel-bordered panel-black">
<div class="panel-heading">
<h3 class="panel-title"><?php echo translate('Total Amount ');?></h3>
</div>
<div class="panel-body">
<div class="text-center">
<h1>
<?php
echo $this->db->select('SUM(amount) as Total');
$getData = $this->db->get_where('tablename',array('amount = '!=0))->first_row();
echo $getData->Total;
?>
</h1>
</div>
</div>
</div>
</div>
try this
<?php
$data = $this->db->get_where('tablename',array('amount = '=>1))->sum(amount)->result();
foreach($data as $row):
echo $row['amount']; //if array output
echo $row->amount; //object output
endforeach;
?>
<div class="col-md-4 col-lg-4">
<div class="panel panel-bordered panel-black">
<div class="panel-heading">
<h3 class="panel-title"><?php echo translate('Total Amount ');?></h3>
</div>
<div class="panel-body">
<div class="text-center">
<h1>
<?php
echo $this->db->select('SUM(amount) as Total');
$getData = $this->db->get_where('tablename',array('amount = '!=0))->first_row();
echo $getData->Total;
?>
</h1>
</div>
</div>
</div>
</div>
Related
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>
I am fetching some results in a loop which is then output into a table - but when applying a 'switch' element from Buefy (Bulma UI kit) it will only apply it to the first item in the row and not anything following.
Here is the HTML of my loop:
<?php
$query = $conn->prepare("SELECT *
FROM dashboard");
$query->execute();
$result = $query->fetchAll();
?>
<div class="container">
<div class="wrapper">
<div class="dashTable">
<div class="header">
<div class="col">Name</div>
<div class="col">Status</div>
<div class="col">Created</div>
<div class="col">Options</div>
</div>
<?php foreach($result as $row){ ?>
<div class="body">
<div class="col">
<a title="View New Dashboard" href="../loading.php?dashboard_id=50">
<?php
echo $row['name'];
?>
</a>
</div>
<div class="col">
<!-- CLICK TO UPDATE STATUS -->
status
<div id="app1">
<template>
<section>
<div class="field">
<b-switch v-model="isSwitchedCustom"
true-value="Active"
false-value="Inactive" type="is-success">
{{ isSwitchedCustom }}
</b-switch>
</div>
</section>
</template>
</div>
</div>
<div class="col"><?php echo date( 'd-m-Y', strtotime($row['created_at']) ); ?></div>
<div class="col">
<span class="tag is-warning is-medium">
Edit
</span>
<span id="confirm-delete" class="tag is-danger is-medium" #click="confirmCustomDelete">
Delete
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
I am just not sure why after the first it does not apply to all rows?
I have a list item Album contains 30 albums.
I tried to display all them in the browser with 1 rows contain 3 items.
With code like:
<div class="container">
<div class="row">
foreach($listAlbum as $item) {
<div class="col-md-4">$item['imgUrl']</div>
}
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
</div>
Note: I want for each continues to loop all .col-md-4.
If I again using foreach(listAlbum) through each .row. It will duplicate, I don't want this.
Have any idea to resolve my problem?
Edit: Full structure in .col-md-4:
<div class="news-post standard-post">
<div class="post-gallery">
<img src="upload/news-posts/st1.jpg" alt="">
</div>
<div class="post-content">
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</h2>
<ul class="post-tags">
<li><i class="fa fa-clock-o"></i>27-Nov-2016</li>
<li><i class="fa fa-comments-o"></i><span>23</span></li>
</ul>
</div>
</div>
You need a counter for the $listAlbum items. Increment the counter for each item and check if it is divisible by 3. If it is divisible by 3, re-open the row tag:
<?php
$listAlbum = [
['imgUrl' => 'url1'],
['imgUrl' => 'url2'],
['imgUrl' => 'url3'],
['imgUrl' => 'url4'],
['imgUrl' => 'url5'],
];
echo "<div class='container'>\n\t<div class='row'>\n";
$i = -1;
foreach ($listAlbum as $item) {
if (++$i && $i % 3 == 0)
echo "\t</div>\n\t<div class='row'>\n";
echo "\t\t<div class='col-md-4'>", $item['imgUrl'], "</div>\n";
}
if (++$i % 3)
echo str_repeat("\t\t<div class='col-md-4'></div>\n", 3 - $i % 3);
echo "\t</div>\n</div>";
Sample Output
<div class='container'>
<div class='row'>
<div class='col-md-4'>url1</div>
<div class='col-md-4'>url2</div>
<div class='col-md-4'>url3</div>
</div>
<div class='row'>
<div class='col-md-4'>url4</div>
<div class='col-md-4'>url5</div>
<div class='col-md-4'></div>
</div>
</div>
Try this:
<div class="container">
<div class="row">
<?php $col = 0; foreach($listAlbum as $item) {
if($col && !($col%3)){echo '</div><div class="row">';}
?>
<div class="col-md-4">$item['imgUrl']</div>
<?php $col++; } ?>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
Sample code:
<?php
for($i=1;$i<30;$i++){
$listAlbum[]= 'item '.$i;
}
?>
<div class="container">
<div class="row">
<?php $col = 0; foreach($listAlbum as $item) {
if($col && !($col%3)){echo '</div><div class="row">';}
?>
<div class="col-md-4"><?php echo $item ?></div>
<?php $col++; } ?>
</div>
Try this out, I am not sure of the content of $item['imgUrl']
<div class="container row">
<div class="col-md-12">
<?php foreach($listAlbum as $item) { ?>
<div class="col-md-4"> <?php $item['imgUrl'] ?></div>
<?php } ?>
</div>
</div>
Here Is The Code
<div class="row">
<div class="col-md-9 column">
<div class="services-listing">
<?php if(!empty($data)):
foreach ($data as $rows ) : ?>
<div class="service">
<div class="service-img"><span><img src="dashboard/uploads/<?php echo $rows['img'];?>" alt="" /></div>
<div class="service-detail">
<h3><?php echo $rows['name'];?></h3>
</div>
</div>
<!-- Service -->
<?php endforeach; else : echo "No Record Found Against This Services"; endif;?>
</div>
<!-- Service Listing -->
</div>
i want to start design from <div class="row"> not from <div class="service"> now it repeating this div i want new <div class="row"> genrated after every 6 records
<div class="row">
<div class="col-md-9 column">
</div>
</div>
Looking for something like this, let me know if it works for you
<?php
$start = 6;
$end = 1;
if(!empty($data)){
foreach ($data as $rows ) {
if ($start % 6 == 0) { ?>
<div class="row">
<div class="col-md-9 column">
<?php } ?>
<div class="services-listing">
<div class="service">
<div class="service-img"><span><img src="dashboard/uploads/<?php echo $rows['img'];?>" alt="" /></div>
<div class="service-detail">
<h3><?php echo $rows['name'];?></h3>
</div>
</div>
<!-- Service -->
</div>
<?php if ($end % 6 == 0) { ?>
</div>
</div>
<?php } $start++; $end++;
}
}
else{ echo "No Record Found Against This Services"; }
?>
you need to wrap div row with foreach first and then:
<?php $i = 0; ?>
<?php if(!empty($data)):
foreach ($data as $rows ) : ?>
<?php $i++; ?>
<div class="row">
<div class="col-md-9 column">
<div class="services-listing">
<div class="service">
<div class="service-img"><span><img src="dashboard/uploads/<?php echo $rows['img'];?>" alt="" /></div>
<div class="service-detail">
<h3><?php echo $rows['name'];?></h3>
</div>
<!-- Service -->
</div>
<!-- Service Listing -->
</div>
<!-- col-md-9 column -->
</div>
<!-- Row -->
</div>
<?php if($i%6==0):?>
<div class="row">
<div class="col-md-9 column">
</div>
</div>
<?php endif; ?>
<?php endforeach; else : echo "No Record Found Against This Services"; endif;?>
just please re-check all divs structure to be sure whether all of them are closed
I am using database for retrieving products.
I want to display product in following pattern.
What can be the php Or .net loop code for this ? Help.
<div class="big-row">
<div class="first-row-left">
<div class="product-1a">Product1</div>
<div class="product-1a">Product2</div>
<div class="product-1a">Product3</div>
<div class="product-1b">Product4</div>
<div class="product-1b">Product5</div>
<div class="product-1b">Product6</div>
</div>
<div class="first-row-right">
<div class="bigproduct-right">Product7</div>
</div>
</div>
<div class="single-row">
<div class="product-single-row">Product8</div>
<div class="product-single-row">Product9</div>
<div class="product-single-row">Product10</div>
<div class="product-single-row">Product11</div>
<div class="product-single-row">Product12</div>
</div>
<div class="big-row">
<div class="first-row-left">
<?php
for($i = 0, $intSize = sizeof($arr); $i < $intSize ; $i++){
?> <div class="product-1a"><?php echo $arr['product']; ?></div>
<?php
}
?>
</div>
A small example of for loop