Jump to content

Display totals of each type


busnut

Recommended Posts

The script below is something that i've been trying to work out for the past week or so how to display how many buses of each make of bus in its depot and how many buses for the whole depot.

 

The best I can come up with is the total of all buses in all depots, and only the total of buses will display for the last depot :(

 

Here is the script:

	$allocation=mysql_query("select busno, depot, chassisbody from busfleet WHERE active='Y' ORDER BY depot ASC, chassisbody ASC, busno + 0 ASC ");

  $DepotNameToDisplay = "abc";
  $ChassisToDisplay= "abc";

$totbuses=0;

{
  while($row_allocation=mysql_fetch_assoc($allocation)) {

  $ThisDepotName = $row_allocation['depot'];
  if ($ThisDepotName != $DepotNameToDisplay){
  $DepotNameToDisplay = $ThisDepotName;
  echo "<p><b>$DepotNameToDisplay</b>";
  $totdepot=0;
}

  $ThisChassisName = $row_allocation['chassisbody'];
  if ($ThisChassisName != $ChassisToDisplay){
  $ChassisToDisplay= $ThisChassisName ;
  echo "<br><i>$ChassisToDisplay</i><br>";

}
  echo $row_allocation['busno']; 
  echo " ";
  $totbuses=$totbuses+1;
  $totdepot=$totdepot+1;
}

{	
  echo "<p>total buses for $DepotNameToDisplay: $totdepot"; 
  echo "<hr>";
}

}
  echo "<p>$totbuses buses allocated!";

 

What its suppose to look like is this:

 

depotname

make of bus with total of buses of this make in this depot

list of buses

total of buses in depot

then loops back to make of bus until no more different make of buses available, then loops to the next depot and keeps going and once all depots/makes/buses are displayed, then displays total

and then displays total amt of all buses

And lastly, its suppose to display the <hr> after each depot, which once again will only show once on the very last depot :(

 

One option I tried kept calculating something that was giving some ridiculous figure, so would appreciate some coding assistance please!

Link to comment
Share on other sites

try

<?php
$allocation=mysql_query("select busno, depot, chassisbody from busfleet WHERE active='Y' ORDER BY depot ASC, chassisbody ASC, busno + 0 ASC ");
$DepotNameToDisplay = "abc";
$ChassisToDisplay= "abc";
$totbuses=0;
$not_start = false;
while($row_allocation=mysql_fetch_assoc($allocation)) {

$ThisDepotName = $row_allocation['depot'];
if ($ThisDepotName != $DepotNameToDisplay){
	if ($not_start){
		echo "<p>total buses for $DepotNameToDisplay: $totdepot";
		echo "<hr>";
	}
	$DepotNameToDisplay = $ThisDepotName;
	echo "<p><b>$DepotNameToDisplay</b>";
	$totdepot=0;
	$not_start = true;
}

$ThisChassisName = $row_allocation['chassisbody'];
if ($ThisChassisName != $ChassisToDisplay){
	$ChassisToDisplay= $ThisChassisName ;
	echo "<br><i>$ChassisToDisplay</i><br>";

}
echo $row_allocation['busno'];
echo " ";
$totbuses=$totbuses+1;
$totdepot=$totdepot+1;
}
echo "<p>total buses for $DepotNameToDisplay: $totdepot";
echo "<hr>";
echo "<p>$totbuses buses allocated!";
?>

Link to comment
Share on other sites

Hey, that worked out brilliantly thanks 'sasa', most appreciated. Except can I stretch the friendship abit more, to somehow get a total of how many buses of each bus make also?

 

ie (part in bold):

depot

bus make (total of buses listed of this make)

buses buses buses buses

bus make (total of buses listed of this make)

buses buses buses buses

(total)

 

I tried to add a $totmake in there to display how many buses of each bus make ($chassistodisplay) there is, but failed :( All the responses I got after trying in different areas using a similar format to what had been done gave me '0' counts or some ridiculous high number.

 

And once again, thanks for what you've done so far, certainly something I hadn't even thought of.

Link to comment
Share on other sites

  • 3 weeks later...

Sorry to shunt this topic back to the top, but im still having difficulty in getting the total counts of each make of bus in each depot :(

The best I got was an unrealistic figure and that was because it kept adding rather each set of totals.

I'm still working on the last code posted by 'sasa' as the total depot count works perfectly, just need the individual bus make count to work perfectly (please).

 

Help would be greatly appreciated :)

Link to comment
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.