I need to multiply the price by the quantity to get the total cost but i am not sure how to do this.
This is what i have done so far:
<?php do { ?>
<p align="Center">
<?php echo $row3['unitprice'] ?>
<?php echo $row3['quantity']; ?>
</p>
<?php } while ($row3 = mysqli_fetch_assoc($resultCustomer3))?>
at the moment i am only printing out unit price and the quantity.
how would i multiply the two to get the total?
HELP please!!
Try this
<?php while ($row3 = mysqli_fetch_assoc($resultCustomer3)) {?>
<p align="Center">
<?php echo $row3['unitprice']; ?>
<?php echo $row3['quantity']; ?>
<?php echo $row3['quantity']*$row3['unitprice']; ?>
</p>
<?php } ?>
To multiply two fields in php, you need this code:
$total = $mnth_190 * $rate_190;
After having calculated the result, you can normally output the variable total!
Related
I wondered if anyone could help me combine two blocks of code I have. I have one block looping though items and the start of another block showing a count and hopefully enabling me to display the items looping through in rows by adding a div around them every two items... Heres the first bit of code, the loop:
<?php if(get_field('areas')): ?>
<?php while(has_sub_field('areas')): ?>
<div class="single-area-item six columns">
<p> <img src="<?php the_sub_field('area_icon'); ?>" style="width:100%;"> <p>
<h4> <?php the_sub_field('area_title'); ?> </h4>
<p> <?php the_sub_field('area_info'); ?> <p>
</div>
<?php endwhile; ?>
<?php endif; ?>
I'm using Advance Custom Fields for Wordpress and this is pulling through repeater fields... this displays them just one after the other.
Here's the code I have found to hopefully display them in rows.
<?php
$num = 1;
foreach ( $terms as $term ) {
if($num%2) {
echo '<div class="area-row">';
}
// Other Code
if($num %2) {
echo '</div>';
}
$num++
}
?>
I would like to display them in rows of two...
ONE TWO
THREE FOUR
FIVE SIX
Etc...
So, Im guessing I need to combine the code somehow... I currently have this: but it doesn't seem to work:
<?php
$num = 1;
foreach ( $terms as $term ) {
if($num%2) {
echo '<div class="area-row">';
}
if(get_field('areas')): ?>
<?php while(has_sub_field('areas')): ?>
<div class="single-area-item six columns">
<p> <img src="<?php the_sub_field('area_icon'); ?>" style="width:100%;"> <p>
<h4> <?php the_sub_field('area_title'); ?> </h4>
<p> <?php the_sub_field('area_info'); ?> <p>
</div>
<?php endwhile; ?>
<?php endif; ?>
if($num %2) {
echo '</div>';
}
$num++
}
?>
Okay so it looks like there was a couple of simple issues with this, you had closed the php tag after your if statment and then continued to write php without reopening the php tags. Also there is a slight logic error with the if($num%2) statements as one of these needs to be if, the other needs to be if not, so that the alternate.
Give this code a try and let me know how you get on:
<?php
if(get_field('areas')):
$num = 1;
?>
<?php while(has_sub_field('areas')):
if($num%2) {
echo '<div class="area-row">';
} ?>
<div class="single-area-item six columns">
<p> <img src="<?php the_sub_field('area_icon'); ?>" style="width:100%;"> <p>
<h4> <?php the_sub_field('area_title'); ?> </h4>
<p> <?php the_sub_field('area_info'); ?> <p>
</div>
<?php
if(!$num%2) {
echo '</div>';
}
$num++
endwhile; ?>
<?php endif; ?>
The main reason behind this question was for me to be able to target the third item of the looped through items, as it had padding on it that was breaking the rows that I needed to remove.
I have since found another solution that seems to be working.
By using the nth-child element, I have been able to target and remove the padding on every third item that's looped through - fixing the issue.
.single-area-item:nth-child(3n+3) {
margin-left: 0;
}
This is for rows or 2 items, if it were rows of 3 or 4 then it would need to target every 4th or 5th item respectively.
I am populating an HTML table from a SQL database using php. What I want to do is, I want to limit the number of columns in one row to 4. I tried doing it with CSS using
table.posts{
border:10px;
width:100%;
columns:auto 4;
-webkit-columns:auto 4;
This is the code I have:
<table class="posts">
<tr>
<?php
$respost = mysqli_query($link,"SELECT * FROM posts WHERE post_author=$uid");
while($rowpost = mysqli_fetch_array($respost)) { ?>
<td>
<h3><?php echo $rowpost['post_title']; ?></a></h3>
<h4><?php //echo $rowpost['post_content']; ?></h4>
</td>
<?php
}
?>
</tr>
</table>
There is no problem with the data I get from the db. It's just that it all shows in one row. I want to limit this to just 4 items per row and then break and continue on the next row. What is a simple way to do this?
Try like this
<table class="posts">
<?php
$respost = mysqli_query($link,"SELECT * FROM posts WHERE post_author=$uid");
$row_count=0;
$col_count=0;
while($rowpost = mysqli_fetch_array($respost)) {
if($row_count%4==0){
echo "<tr>";
$col_count=1;
}
?>
<td>
<h3><?php echo $rowpost['post_title']; ?></a></h3>
<h4><?php //echo $rowpost['post_content']; ?></h4>
</td>
<?php
if($col_count==4){
echo "</tr>";
}
$row_count++;
$col_count++;
}
?>
</table>
I have an if statement
<p>Included Services</p>
<?php foreach($services as $service): ?>
<?php if(!empty($service['service_webdesign'])){ ?>
<div><strong>web Design:</strong> <?php echo $service['service_webdesign'] ?></div>
<?php } ?>
<?php endforeach ?>
<p>Services charged by the hour</p>
<?php foreach($services as $service): ?>
<?php if(!empty($service['service_webdesign'])){ ?>
<div><strong>Service:</strong> <?php echo $service['service_webdesign'] ?></div>
<?php } ?>
<?php endforeach ?>
There are three possible values Yes, hourly rate or no.
In the first block I want to be able to echo the service column values
<div><strong>Service:</strong> <?php echo $service['service_webdesign'] ?></div>
only if the database value is 'yes'.
In the second block I want to echo the service fee column
<div><strong>Web Design:</strong> <?php echo $service['service_fee_webdesign'] ?>
</div>
only if the value of the 'service_webdesign' is set to 'hourly rate' but I do not actually want to show the value of 'service_webdesign' ('hourly rate').
An example of my database table structure is as follows
service_webdesign = Yes
service_fee_webdesign = NULL
service_graphicdesign = Hourly
service_fee_graphicdesign = 20
How can I achieve that within an if statement? Or would I need to create another SQL query for each of the blocks?
I am using a page to display order details and want to show invoice no and date in that page. Please tell me how to show invoice no. Here is the code:
<div class="col-sm-4 invoice-`co`l">
<b>Order No. </b>#
<?php if ($this->getNoUseOrderLink()): ?>
<?php echo $_order->getRealOrderId(); ?>
<?php else: ?>
<?php echo $_order->getRealOrderId(); ?>
<?php endif; ?>
<br>
<b>Amount:</b> <?php echo " ".$this->gettotalamount(); ?><br>
<b>Payment Type:</b> <?php echo $_order->getPayment()->getMethodInstance()->getTitle(); ?>
Below is the code snippet to get Invoice info associated with any order. Based on your code, you have already loaded order model on $_order, so try below code.
<?php
// ignore below two lines if you already have order model
// $_order=Mage::getModel('sales/order')->loadByIncrementId($anyorderincrementid);
// $_order=Mage::getModel('sales/order')->load($anyorderentityid);
if ($_order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($_order->getInvoiceCollection() as $inv) {
echo "Invoice Id- ".$inv->getIncrementId();
echo "Invoice Date- ".date('d-m-Y',strtotime($inv->getCreatedAt()));
}
}
?>
To get date in d-m-y format (answer of your question which is in comments)
<?php
// format admin and store date
$orderAdminDate=date('d-m-y',strtotime($orderAdminDate));
$orderStoreDate=date('d-m-y',strtotime($orderStoreDate));
echo $orderAdminDate;
if ($orderAdminDate != $orderStoreDate):
echo date('d-m-y',strtotime($_order->getCreatedAtStoreDate()));
echo $orderStoreDate;
endif;
?>
I'm working on a website. My client want me to show the weight of product. But the condition is if the weight is less than a Kg, it should show the grams. If it is more than a kg it should show the kg along with fraction point i,e if the weight is 1 kg 350 grams then it should show 1.35 Kg. My code for it goes like this.
<?php $_weight = $_product->getweight()?>
<?php if ($_weight >= 1) : ?>
<span><?php echo($_weight)?>Kg<span>
<?php else: ?>
<? $_weight1=($_weight * 1000) ?>
<span><?php echo(round($_weight1))?>grams<span>
<?php endif;?>
<br/>
But I don't know how to show the kg with only two fraction numbers. Please help me. I'm a budding developer.
You almost got there - when you use the round() function you can specify the decimal precision as the 2nd parameter.
<span><?php echo($_weight)?>Kg<span>
becomes
<span><?php echo(round($_weight,2))?>Kg<span>
http://php.net/round
<? $_weight1=($_weight * 1000) ?> line replace with <?php $_weight1=($_weight * 1000) ?> and try...
<?php $_weight = $_product->getweight(); ?>
<?php if ($_weight >= 1) { ?>
<span><?php echo round($_weight,2); ?>Kg<span>
<?php }else{ ?>
<?php $_weight1= round($_weight * 1000); ?>
<span><?php echo $_weight1; ?>grams<span>
<?php } ?>
<br/>