Jump to content

Recommended Posts

hello , Im working on a fictional web-site as a final project for my course.
Im having a little trouble with placing php includes in my page and also printing the total sum of my order.
also im not sure how or where to place the order now button in order.php'\.

here is my git , most of the necessery code if found in order.php

https://github.com/niksou/ProjectWeb

webbb.png

Link to comment
https://forums.phpfreaks.com/topic/311270-small-project-help/
Share on other sites

<

<h3>Order Details</h3>

<div class="table-responsive">

<table class="table table-bordered">

<tr>

<th width="40%">Item Name</th>

<th width="10%">Quantity</th>

<th width="20%">Price</th>

<th width="15%">Total</th>

</tr>

<?php

$total=0;

$itemCount=0;

$first=false;

for($i=0;$i<6;$i++) {

$title = ($_POST['hidden_name'.$i]);

$price = ($_POST['hidden_price' . $i]);

$quantity = ($_POST['quantity' . $i]);

?>

<?php

if($quantity>0){

$shortStr= substr($price,1,-1);

$flatVal=(float)$shortStr;

$flatVal=$flatVal*$quantity;

$totalItem=$flatVal*$quantity;

$total+=$flatVal;

?>

<tr>

<td><?php echo $title; ?></td>

<td><?php echo $quantity; ?></td>

<td> <?php echo $price; ?></td>

<td> <?php echo $totalItem;?></td>

<td>

</tr>

<?php

}

if($i==5){

echo"Order total : $total";

}

}

?>

<br>

<br>

<br>

>

Link to comment
https://forums.phpfreaks.com/topic/311270-small-project-help/#findComment-1580300
Share on other sites

1. please use the code icon (<>) and specify PHP. It makes your code much easier to read.

2. learn to indent your code.

3. what is up with ?> and <?php  and no intervening HTML? It makes it very difficult to see where your code blocks end.

Your code should look more like this:

for($i=0;$i<6;$i++) {
   $title = ($_POST['hidden_name'.$i]);
   $price = ($_POST['hidden_price' . $i]);
   $quantity = ($_POST['quantity' . $i]);
   if($quantity>0){
      $shortStr= substr($price,1,-1);
      $flatVal=(float)$shortStr;
      $flatVal=$flatVal*$quantity;
      $totalItem=$flatVal*$quantity;
      $total+=$flatVal;
  }
}

I didn't include everything in the loop and if blocks as it is too difficult to follow but you should get the idea.

Edited by gw1500se
Link to comment
https://forums.phpfreaks.com/topic/311270-small-project-help/#findComment-1580317
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.