Page 1 of 1

Table is unorganized and confusing

Posted: Tue Feb 03, 2015 8:26 am
by saminbhp
Hi. I'm new here.

I need help with the tables. They are not organized/neat. (http://i.imgur.com/1LLpQ2G.png)

The tables have to look neat, understandable and not confusing. Someone help me. Below is the code.

Code: Select all

<table>
			<?php
				$result = $mysqli->query("SELECT * FROM `order`");
				while($obj = mysqli_fetch_assoc($result)) {
					$orderDate = $obj['OrderDate'];
					$orderId = $obj['OrderID'];
					$totalAmount = $obj['OrderTotal'];
					$paymentStatus = $obj['PaymentStatus'];
					$customerId = $obj['CustomerID'];
					$res = $mysqli->query("SELECT CustomerName, CustomerContactNo, CustomerEmail FROM customer WHERE CustomerID=$customerId");
					if($row = mysqli_fetch_assoc($res)) {
						$customerName = $row['CustomerName'];
						$customerContactNo = $row['CustomerContactNo'];
						$email = $row['CustomerEmail'];
					}
				?>
				<tr>
					<th>Customer Name</th>
					<th>Customer Contact</th>
					<th>Customer Email</th>
					<th>Order ID</th>
					<th>Order Date</th>
					<th>Total Amount</th>
				</tr>
				<tr>
					<td><?php echo $customerName;?></td>
					<td><?php echo $customerContactNo;?></td>
					<td><?php echo $email;?></td>
					<td><?php echo $orderId;?></td>
					<td><?php echo $orderDate;?></td>
					<td>$<?php echo $totalAmount;?></td>
				</tr>
				<?php
					$result1 = $mysqli->query("SELECT * FROM ordermenu WHERE OrderID = $orderId");
					while($obj1 = mysqli_fetch_assoc($result1)) {
						$menuId = $obj1['MenuID'];
						$menuQty = $obj1['menuQty'];
						$result2 = $mysqli->query("SELECT * FROM menu WHERE MenuID = $menuId");
						$obj2 = mysqli_fetch_assoc($result2);
						$name = $obj2['MenuName'];
						$price = $obj2['MenuPrice'];
					?>
					<tr>
						<th>Menu Name: <?php echo $name;?></th>
						<th>Menu Price: <?php echo $price;?></th>
						<th>Menu Quantity: <?php echo $menuQty;?></th>
					</tr>
					<?php } ?>
					<tr>
						<td><a href="update_order.php?id=<?php echo $orderId;?>">Update Order Total</a></td>
					</tr>
				<?php } ?>
			</table>

Re: Table is unorganized and confusing

Posted: Tue Feb 03, 2015 1:56 pm
by requinix
What do you want it to look like? More precisely than "neat, understandable and not confusing".

Re: Table is unorganized and confusing

Posted: Tue Feb 03, 2015 5:24 pm
by saminbhp
I want it to look like this -> http://i.imgur.com/R3iqFzz.png.

That is just an example. Some tables are merge and whatnot. Please help me.

Re: Table is unorganized and confusing

Posted: Tue Feb 03, 2015 5:45 pm
by requinix
Here is the HTML you need to generate just for Member 1's rows:

Code: Select all

	<tr>
		<td rowspan="2">Member 1</td>
		<td rowspan="2">84550</td>
		<td rowspan="2">Member1@gmail.com</td>
		<td rowspan="2">1</td>
		<td rowspan="2">02/09/2015</td>
		<td>Kebab</td>
		<td>$2</td>
		<td>1</td>
		<td rowspan="2">$5</td>
		<td rowspan="2">Update</td>
	</tr>
	<tr>
		<td>Coke</td>
		<td>$3</td>
		<td>1</td>
	</tr>
The "rowspan=2" is how a cell spans multiple rows. In this case there are two order items so those cells need to span two rows. The order item information gets one regular cell. The second row only includes cells that are not spanning over this row. No name, contact number, email, etc. and only the order item information.

Member 2 is exactly the same:
- rowspan=3 to span three rows for the three order items
- first row includes all cells and the first item
- second and third rows include only cells for the second and third items respectively

Do you want to give a shot to coding that? Loop over each member you want to output and show just their first item, set rowspan= according to the number of items in the order, even if it's just one. Then loop over all of the order items except the first one and output their information.
Roughly,

Code: Select all

for each customer {
	$count = count of order items

	show a row with all information for the customer, using cells with rowcount=$count, and including information for just the first order item

	for each order item after the first {
		show a row with just that item's information
	}
}

Re: Table is unorganized and confusing

Posted: Tue Feb 03, 2015 6:10 pm
by saminbhp
FOR loop is what I have problems with. I would appreciate it if you could rewrite the code. Please.

Re: Table is unorganized and confusing

Posted: Tue Feb 03, 2015 6:32 pm
by requinix
The code you've posted is very different from what I said. Have you already changed that and you're stuck with the for loop? What do you have now?

Re: Table is unorganized and confusing

Posted: Wed Feb 04, 2015 7:32 am
by saminbhp
I can't do it. I really can't :'(