vanessia_1999 0 Junior Poster in Training

HI everyone I thought I got it, because last time I was having problem with the information being displayed until someone told me to have consistant column.

I fix that problem, adn thought it would be not problemto add another column.

I added another column and now the quantity sold is not matching from what the database. I know my code is right because I ask it to come out of order_items.quantity. Therefore, it is not coming out of another table. At first when I had 6 column it was working fine. But now since I added another column the quantity is showing riduculous number making the total wrong. The quantity should be 101 and I am getting 93425

I don't get it. Is it how I set up the column again?

$query = "SELECT products.description, sum(order_items.quantity) as total, products.price, orders.date, color_list.item_color, store_item_size.item_size ";
   $query .= " from orders, order_items, products, color_list, store_item_size";
   $query .= " WHERE orders.orderid = order_items.orderid";
   $query .= " AND order_items.prodid = products.prodid";
   $query .= " AND orders.status = 'shipped'";
   $query .= " AND orders.date >= '$dbstartdate' AND orders.date <= '$dbenddate'";
   $query .= " GROUP BY products.description";

   $result = mysql_query($query);

   echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\">\n";
   echo "<tr><td colspan=\"7\"><b>Products sold between " . $startdate . " and " . $enddate . "</b></td></tr>\n";
   echo "<tr><td><b>Product</b></td><td><b>Quantity Sold</b></td><td><b>Unit price</b></td><td><b>Total</b></td><td><b>Purchase Date</b></td><td><b>Item Color</b></td><td><b>Item Size/Length</b></td></tr>\n";
   $count = 3;
   while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
   {
      $product = $row['description'];
      $quantity = $row['total'];
      $price = $row['price'];
	  $date = $row['date'];
	  $item_color = $row['item_color'];
	  $item_size = $row['item_size'];
	  $total = $quantity * $price;
      echo "<tr><td>$product</td><td>$quantity</td>\n";
      printf("<td>%.2f</td><td>=B%s * C%s</td><td>$date</td><td>$item_color</td><td>$item_size</td></tr>\n", $price, $count, $count);
      $count++;
   }
   $count--;
   echo "<tr><td><b>Total</b></td><td>=SUM(B3:B" . $count . ")</td><td>&nbsp;</td>\n";
   echo "<td>=SUM(D3:D" . $count . ")</td></tr>\n";
   echo "</table>\n";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.