Php Math coding aka totals help

Sry this code has been posted before I just need a bit more help . when I select the winners of the bids id like a box at the bottom with the total of the bids I chose as a winner and it needs to be zero by defalt Since No winner is the first option in the dropdown menu.

[php]

Quantity
Unit(s)
Description
All Vendor Prices
                        <!--/*for($colIterator=0; $colIterator<$vendorResponseCounter; $colIterator++){
                        //echo "<th scope=\"col\">$vendorName[$colIterator]</th>";
                        }*/
                        //echo "<th scope=\"col\">Lowest for this item</th>";-->
                        <?php
                        // loop to create table with bid items and qtys
                        for($i=0; $i<$counterArrayBidItems; $i++){
                            echo "<tr>";
                            echo "<td>$arrayBidQtys[$i]</td>";
                            echo "<td>$arrayBidItems[$i]</td>";
                            echo "<td>$arrayBidDescr[$i]</td>";
                            ?>
                            <td>
                            
                           <select name="Winning bid[]">
                            echo '<option value="No_Winner">No Winner</option>';

                            <?php
                            
                            // nested for loop to load the cherry picker lowest price for a row
                            for($cpIterator=0; $cpIterator<$vendorResponseCounter; $cpIterator++){
                                
                                $cpArrayLowestPrice[$cpIterator] = $mainArrayVendorPrices[$cpIterator][$i];
                            }
                            
                            // nested for loop to output undetermined number of cells in the table row
                            for($rowIterator=0; $rowIterator<$vendorResponseCounter; $rowIterator++){
                                if($mainArrayVendorPrices[$rowIterator][$i] != "0" && $mainArrayVendorPrices[$rowIterator][$i] != null && $mainArrayVendorPrices[$rowIterator][$i] != '')
                                {
                                    $dsc = $mainArrayVendorPrices[$rowIterator][$i];
                                    $ttlaz = floatval($dsc);// * $arrayBidQtys[$i];
                                    if($dsc > 0)
                                    {
                                        $dsc = '$'  . number_format($ttlaz,2);
                                    }
                                    else
                                    {
                                        $dsc = '';
                                    }
                                    echo '<option value="' . $vendorid[$rowIterator] .'">'.$vendorName[$rowIterator]. ' - ' . $dsc .'</option>';
                                }
                            }
                            ?>
                            </select>
                            </td>[/php]

I know the code for the boxes will be somthing like that

[php]

$
[/php]

What I hope I am saying is in the drop down boxes you can pick a winner for the bids or pick no winner for the bid. I just need it to add the totals of all the winning bids at the bottom

Well, not really sure what you need, but, if you have an array called winning_bid[] , you could just do a for loop thru it and add the values and place it where you want it. Since you have a “no_winner” option in your drop-down, just check for not equal to that and if it is not equal to it add the value to the running total.

Hope that makes sense…

Thanks . what I am needing is with that code is help with adding up all the winning bids. Via the drop down boxes you can selected winning bids. Once you select the winning bids or selecting no winner. I need a Total of all the winning bids you selected at the bottom. either via you pressing a button or it auto doing the totals after you select the winners of the Item.

Would I use something like a Count array ?? and example of one here

[php]<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = count($a);
// $result == 3

$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
$result = count($b);
// $result == 3

$result = count(null);
// $result == 0

$result = count(false);
// $result == 1
?>
[/php]

That’s not exactly what you asked about before. So, to SUM up an array, you just use that command:

$result = array_sum($a);

If that is what you need, you are all set. If you are using an array that has mixed strings and numbers, you have to parse thru them to get the numbers only.

Hope that helps!

PS: There are tons of math functions in PHP. ALL of them are listed in the PHP manual. Here is where I found this info for you. http://php.net/manual/en/function.array-sum.php

here is what I am needing. on this site people bid on items and then venders select the winning bid via that Code I pasted via a dropdown box. once they select the winning bid or bids and there final. I need the total of the winning bids displayed at the bottom.

Well, if your array is: $arrayBidQtys[$i]

You just SUM it up like this: $total = array_sum($arrayBidQtys);

Note NO brackets are used, just the variable name!

Should work!

thanks you rock. Where abouts in the code should I place it ?

Well, that’s a problem. First, when someone DROPS-DOWN a selection and selects a winning bid, usually the page just sits there. Drop-downs do NOT trigger a form posting. If the page is posted out to a totalling PHP script, then you would do the totals there and display it however you wanted. If the totals need to be LIVE on the page without it being posted out to a script, then you would have to use Javascript or JQuery to capture the changes in the drop-downs and trigger a total change.

One problem with helping on line is that we can not see ALL of your code and how every part fits together.
You posted a sample drop-down. But, in your sample, there is no posting code. So, we are not sure what is next for you.

My guess is that when a winning bid is selected, the form is posted by the producer of the product. So, at that point the page runs some script to enter this info. If you are sitting at the one page that has all the running bids in front of you , there is a button you press when ALL the bids are in. That button would post the drop-down form to the script. Not sure if this helps you at all… If not, we would need a step-by-step explanation of how your system works overall or at least more info on what you want this total done with.

Hope that helps a little…

Thanks ill give you more info now. This is a Bigger Verson of our code. what Page I am trying to fix is called the A to Z page and get the totals from the dropdown boxes. This is the start of the Awards Recommendation Page and you can tab between Cherry Picker,Lowest Total Bid, and A-Z . I hope this helps you help me Will be in two parts[php]<?php
}

}

//postrecip used to be here

//addbid used to be here

/*if($_GET['action'] == "status"){
if($_GET['bid']){
$bid = $_GET['bid'];
$q = "SELECT * FROM `tbl_bids` WHERE `bid_id` = \"$bid\"";
$result=mysql_query($q);
$num=mysql_numrows($result);			
if($num != 0){
for($i=0;$i<$num;$i++){
$bid_name = mysql_result($result,$i,'bid_name');
$bid_contact = mysql_result($result,$i,'bid_contact');
$bid_phone = mysql_result($result,$i,'bid_phone');
$bid_fax = mysql_result($result,$i,'bid_fax');
$bid_email = mysql_result($result,$i,'bid_email');
$bid_address = mysql_result($result,$i,'bid_address');
$bid_address2 = mysql_result($result,$i,'bid_address2');
$bid_city = mysql_result($result,$i,'bid_zip');
$bid_state = mysql_result($result,$i,'bid_state');
$bid_zip = mysql_result($result,$i,'bid_zip');
$bid_attachment = mysql_result($result,$i,'bid_attachment');
echo "$bid_name<br />$bid_contact<br />$bid_phone<br />$bid_fax<br />$bid_email<br />$bid_address<br />$bid_address2<br />$bid_city<br />$bid_state<br />$bid_zip<br />$bid_attachment";
}
}	
}
}*/

if($_GET['action'] == "status"){ //SHOW THE STATUS OF THE BID WITH VENDORS
	if($_GET['bid']){
		$bid = $_GET['bid'];
		
		$q = "SELECT * FROM `tbl_reference` WHERE `bid_id` = \"$bid\"";
		$result=mysql_query($q);
		$num=mysql_numrows($result);
		
		$qStatus = "select `bid_status` from `tbl_bids` where `bid_id` = \"$bid\"";
		$result3 = mysql_query($qStatus);
		$bidstatus = mysql_result($result3,0,"bid_status");
		
		$q5 = "SELECT * FROM tbl_bids WHERE bid_id='$bid'";
		$r5 = mysql_query($q5);
		$n5 = mysql_num_rows($r5);
		for($l=0;$l<$n5;$l++){
			$aBidItemQty = mysql_result($r5,$l,"bid_item_qty");
			$aBidItemUnit = mysql_result($r5,$l,"bid_item_unit");
			$aBidItemDescr = mysql_result($r5,$l,"bid_item_descr");
		}
		$arrBIQ = explode("~",$aBidItemQty);
		$arrBIU = explode("~",$aBidItemUnit);
		$arrBID = explode("~",$aBidItemDescr);
		
		$q6 = "SELECT * FROM tbl_submissions WHERE sub_bid_id='$bid'";
		$r6 = mysql_query($q6);
		$n6 = mysql_num_rows($r6);
        $vendorIBPDonations = array();
        $vendorIBPDonation = null;
		for($m=0;$m<$n6;$m++){
			$arrBTP = mysql_result($r6,$l,"bid_total_prices");
			$arrBTPa = explode("~",$arrBTP);
            $vendorIBPDonation = mysql_result($r6,$m,"bid_total_donations");
            $vendorIBPDonations[] = explode("~", $vendorIBPDonation);
			for($o=0;$o<count($arrBTPa);$o++){
				$arrDDBTP[$m][$o] = $arrBTPa[$o];
			}			
		} // end main if
		
        
		if($num != 0){
			for($i=0;$i<$num;$i++){
				$vendors = explode(",",mysql_result($result,0,"vendors"));
				$b=0;
				//$vendoroptions = '<option value="" selected>Select A Vendor</option>';
				foreach($vendors as $vendor){
					$qCompanies = "SELECT * FROM tbl_companies LEFT JOIN tbl_submissions ON company_id = sub_company_id WHERE `company_id` = \"$vendor\" AND `sub_bid_id` = \"$bid\"";
					//$q = "SELECT * FROM `tbl_submissions` WHERE `sub_company_id` = \"$vendor\"";
					
					
					$result2 = mysql_query($qCompanies);
					$status = mysql_result($result2,0,"sub_status");
					$file = mysql_result($result2,0,"sub_details");
					$companyname = mysql_result($result2,0,"company_name");
					$companyID = mysql_result($result2,0,"company_id");
					//$result2 = mysql_query($q);
					//$status = mysql_result($result2,0,"sub_status");
					//$file = mysql_result($result2,0,"sub_details");
					
					$total = mysql_result($result2,0,"sub_total");
					$discount = mysql_result($result2,0,"sub_discount");
					$cashback = mysql_result($result2,0,"sub_cashback");
					
					$discount2 = $total * ($discount / 100);
					$cashback2 = $total * ($cashback / 100);
					
					$discount2 = number_format($discount2, 2);
					$cashback2 = number_format($cashback2, 2);
					
					
					
					switch($status){
                        case 0: $status = "No Action Taken Yet"; 
                            break;
                        case 1: $status = "<a href=\"files/submissions/$file\">Vendor Responded</a>";
                            break;
                        case 2: $status = "<span style=\"color:#ff0000\">Declined to bid</span>";
                            break;
					}
					
					$vendor_list[$b] = mysql_result($result2,0,"company_name");
					$vendorName[$b] = mysql_result($result2,0,"company_name");
					$vendorid[$b] = mysql_result($result2,0,"company_id");
					$vendor_list[$b] .= " - STATUS: ".$status ." - Total: $$total - IBP Amount %: $cashback% / $$cashback2";
					
					
					if ($total <> "0") {
                        $vendoroptions .= "<option value=\"".mysql_result($result2,0,"company_id")."\" >".mysql_result($result2,0,"company_name")."</option>";
					}
					$b++;
				}
				//$vendor_array = explode(",",$vendor_list);
			}
			/*echo "<h1>Bid Status</h1><br />".count($vendor_list)." vendors bidding:<br />";
			$j = 0;
			foreach($vendor_list as $vendor){
            
            if ( $j&1 ) {
            $spanClass = "background-color: white; height: 20px; width: 700px; border-bottom: 1px solid silver; margin: 5px;";
            } else {
            $spanClass = "background-color: #ffffcc; height: 20px; width: 700px; border-bottom: 1px solid silver; margin: 5px;";
            }
            echo "<div style=\"$spanClass\">$vendor </div>";
            $j++;
			}
			
			$rows = count($arrBIQ);
			$cols = count($vendors);*/?>
<?php /* <?php for($i=0;$i<$cols;$i++){ ?>
            <th scope="col"><?php echo $vendorName[$i];?>&nbsp;</th>
            
			<?php
            }echo "</tr>";
            for($j=0;$j<$rows;$j++){
            ?>
            <tr>
            <td><?php echo $arrBIQ[$j]; ?>&nbsp;</td>
            <td><?php echo $arrBIU[$j]; ?>&nbsp;</td>
            <td><?php echo $arrBID[$j]; ?>&nbsp;</td>
            <?php for($k=0;$k<$cols;$k++){ ?>
            <td><?php echo $arrDDBTP[$j][$k]; ?>&nbsp;</td>
            <?php } ?>
            </tr>
            <?php
            }
			echo "</table>";
            <?php */


            // grab bid id from url
            $urlBidId = $_GET['bid'];
            
            // get vendor responses for current bid
            $bidVendorsQuery = "SELECT * FROM tbl_bids, tbl_submissions WHERE tbl_bids.bid_id='$urlBidId' AND tbl_bids.bid_id = tbl_submissions.sub_bid_id";
            $bvqResult= mysql_query($bidVendorsQuery);
            
            // get only bid information for current bid
            $bidInfoQuery = "SELECT * FROM tbl_bids WHERE bid_id='$urlBidId'";
            $biqResult = mysql_query($bidInfoQuery);
            
            // get company info for current bid vendors
            /*
Qty Units Description

[php]* CODE FOR THIS EXISTS, PLUGIN HERE -> ALREADY SHOWS ALL CURRENT VENDORS AND COMPANY NAMES ON AWARDS PAGE
*/

            // number of vendor responses for current bid
            $vendorResponseCounter = mysql_num_rows($bvqResult);
            //$vendorResponseCounter = 20;
            $bidInfoCounter = mysql_num_rows($biqResult);
            
            // get items, qty, and descriptions from the current bid 
            for($i2=0; $i2<$bidInfoCounter; $i2++){
                $bidUnits = mysql_result($biqResult,$i2,"bid_item_unit");
                $bidQtys = mysql_result($biqResult,$i2,"bid_item_qty");
                $bidDescriptions = mysql_result($biqResult,$i2,"bid_item_descr");
            }
            
            //print_r($bidUnits);
            
            // arrays of items and qtys
            $arrayBidItems = explode("~",$bidUnits);
            $arrayBidQtys = explode("~", $bidQtys);
            $arrayBidDescr = explode("~",$bidDescriptions);
            
            // counters for arrays
            $counterArrayBidItems = count($arrayBidItems);
            $counterArrayBidQtys = count($arrayBidQtys);
            $counterArrayBidDescr = count($arrayBidDescr);
            
            $schoolId = $_SESSION["sid"];
            $feeQuery = "select tbl_client_fee.percentage 'percentage' from tbl_schools left join tbl_systems on tbl_schools.school_system = tbl_systems.system_id left join tbl_client_fee on tbl_systems.system_id = tbl_client_fee.client_id where school_id = $schoolId";
            $feeResults = mysql_query($feeQuery);
            $purchaserFee = mysql_result($feeResults,0,"percentage");
            if(!$purchaserFee )
            {
                $purchaserFee = 0.15;
            }
            else
            {
                $purchaserFee =  floatval($purchaserFee)/floatval(100);
            }
            // load vendor responses into a two dimensional array
            $mainArrayVendorIds = array();

            for($vendorLoad=0; $vendorLoad<$vendorResponseCounter; $vendorLoad++){

                $currentVendorPrices = mysql_result($bvqResult,$vendorLoad,"bid_unit_prices");

                $mainArrayVendorIds[] = mysql_result($bvqResult,$vendorLoad,"sub_company_id");

                $arrayCVP = explode("~",$currentVendorPrices);

                $counterArrayCVP = count($arrayCVP);

                for($innerVendorLoad=0; $innerVendorLoad<$counterArrayCVP; $innerVendorLoad++){

                    $mainArrayVendorPrices[$vendorLoad][$innerVendorLoad] = round($arrayCVP[$innerVendorLoad] * $arrayBidQtys[$innerVendorLoad] - $vendorIBPDonations[$vendorLoad][$innerVendorLoad] + $vendorIBPDonations[$vendorLoad][$innerVendorLoad] * $purchaserFee, 2);

                }

            }
            
            $lowestTotalPrices = array();
            for($i = 0; $i < $vendorResponseCounter; $i++)
            {
                $lineCount = count($mainArrayVendorPrices[$i]);
                $lowestTotalPrices[$i] = array(); 
                $lowestTotalPrices[$i][] = $vendorid[$i];
                $lowestTotalPrices[$i][] = $vendorName[$i];
                $lowestTotalPrices[$i][] = array();
                $lowestTotalPrices[$i][] = 0.00;
                for($j = 0; $j < $lineCount; $j++)
                {
                    $lowestTotalPrices[$i][2][] = $mainArrayVendorPrices[$i][$j];
                    $lowestTotalPrices[$i][3] += $mainArrayVendorPrices[$i][$j];
                }
            }
            $lowestTotal = 2147483647;
            $lowestTotalWinningIdx = 0;
            for($i=0; $i < count($lowestTotalPrices); $i++)
            {
                if($lowestTotalPrices[$i][3] < $lowestTotal && $lowestTotalPrices[$i][3] > 0)
                {
                    $lowestTotal = $lowestTotalPrices[$i][3];
                    $lowestTotalWinningIdx = $i;
                }
            }

			
			if ($_SESSION['pbuy'] == 1) {
                if($bidstatus != "5"){
                    $priceDescription = "Prices shown are total vendor price minus IBP plus Biducation payment";
                    //echo count($vendoroptions);
                    if (count($vendoroptions) > 0) { ?>
                        <div id="vendorAwards" class="TabbedPanels">
			                <ul class="TabbedPanelsTabGroup">
			  	                <li class="TabbedPanelsTab" tabindex="0">Cherry Picker</li>
				                <li class="TabbedPanelsTab" tabindex="1">Lowest Total Bid</li>
				                <li class="TabbedPanelsTab" tabindex="2">A-Z</li>
			                </ul>
			                <div class="TabbedPanelsContentGroup">
                        <?php
                        
                        
                        $newBidVendorsQuery = "SELECT * FROM tbl_bids, tbl_submissions WHERE tbl_bids.bid_id='$urlBidId' AND tbl_bids.bid_id = tbl_submissions.sub_bid_id AND sub_status = 1";
                        $result = mysql_query($newBidVendorsQuery);
                        for($i=0;$i<mysql_num_rows($result);$i++){
                            $rows[] = mysql_fetch_assoc($result);   
                        }
                        foreach($rows as $row){
                            $quantities = explode('~', $row['bid_item_qty']);
                            $descriptions = explode('~', $row['bid_item_descr']);
                            $units = explode('~', $row['bid_item_unit']);
                            $prices = explode('~', $row['bid_unit_prices']);
                            $ibps = explode('~', $row['bid_total_ibps']);
                            $numProducts = count($descriptions);
                            
                            for($i=0;$i<$numProducts;$i++){
                                $products[$i] = array(
                                    'quantity' => $quantities[$i],
                                    'description' => $descriptions[$i],
                                    'unit' => $units[$i],
                                    'price' => $prices[$i],
                                    'ibp' => $ibps[$i]
                                );
                            }
                            
                            $fixed[$row['sub_company_id']] = array(
                                'id' => $row['sub_company_id'],
                                'products' => $products
                            );
                        }
                        $sql = "SELECT * FROM tbl_vendors, tbl_vendor_ref WHERE tbl_vendors.user_id = tbl_vendor_ref.uid AND tbl_vendor_ref.vid IN (" . implode(", ", array_keys($fixed)) . ")";
                        $result = mysql_query($sql);
                        for($i=0;$i<mysql_num_rows($result);$i++){
                            $vendor = mysql_fetch_assoc($result);
                            $fixed[$vendor['vid']]['name'] = $vendor['user_fname'];
                        }
                        foreach($fixed as $singleVendor){
                            foreach($singleVendor['products'] as $singleProduct){			    	
                                $singleItem['quantity'] = $singleProduct['quantity'];
                                $singleItem['units'] = $singleProduct['unit'];
                                $singleItem['description'] = $singleProduct['description'];
                                $items[] = $singleItem;
                            }
                            break;
                        }
                        function nonZero($a){
                            return ($a > 0);
                        }
                        for($i = 0; $i < $numProducts; $i++){
                            foreach($fixed as $key => $singleVendor){
                                $price[$key] = $singleVendor['products'][$i]['price'];
                            }
                            $min_prices[$i] = min(array_filter($price, 'nonZero'));
                        }
                        for($i = 0; $i < $numProducts; $i++){
                            $lowestPrice = array('id' => 0, 'price' => 0, 'ibp' => 0);
                            foreach($fixed as $key => $singleVendor){
                                $singleProduct = $singleVendor['products'][$i];
                                if($singleProduct['price'] != 0){
                                    if($min_prices[$i] === $singleProduct['price'] && $singleProduct['ibp'] > $lowestPrice['ibp']){
                                        $lowestPrice = array('id' => $key, 'price' => $singleProduct['price'], 'ibp' => $singleProduct['ibp']);
                                    }
                                }
                            }
                            $king_of_the_hill[$i] = $lowestPrice['id'];
                        }
                        foreach($items as $key => $value){
                            $id = $king_of_the_hill[$key];
                            $items[$key]['lowest_vendor'] = array(
                                 'id' => $id,
                                 'name' => $fixed[$id]['name'],
                                 'price' => $fixed[$id]['products'][$key]['price']
                             );
                        }
                        ?>

[php]



Awards Recommendation Page


<?php echo $priceDescription; ?>






<?php
$columnTotals = array();
foreach($vendorName as $vn)
{
$columnTotals[] = 0;
?>

<?php
}
?>

<?php
$idx = 0;
$winningTotal = 0;
foreach($items as $item){
$winningVendorIdx = 0;
$lineQty = intval($item[‘quantity’]);
?>




<?php
                            $lowestFound = false;
                            $secondLowestFound = false;
                            $lowestLinePrice = 0;
                            $lowestLineExtend = 0;
                            $rIdx = 0;
                            foreach($mainArrayVendorPrices as $vp)
                            {
                                $rIdx++;
                                $lowest = 2147483647;
                                $secondLowest = 2147483647;
                                $cpStyle = 'style="text-align:center;"';
                                $temp = 'No Bid';
                                
                                if($vp != null && $vp != '' && $vp != '0')
                                {
                                    $temp = $vp[$idx];
                                    if($temp == null || $temp == '' || $temp == '0')
                                    {
                                        $temp = 'No Bid';
                                    }
                                    else{
                                        $temp = floatval($temp);
                                        $ttlIdx = 0;
                                        foreach($mainArrayVendorPrices as $p)
                                        {
                                            if(intval($p[$idx]) != 0)
                                            {
                                                $columnTotals[$ttlIdx] += floatval($p[$idx]);// * floatval($lineQty);
                                                if(floatval($p[$idx]) < floatval($lowest))
                                                {
                                                    $secondLowest = $lowest;
                                                    $lowest = floatval($p[$idx]);
                                                    $winningVendorIdx = $ttlIdx;
                                                }
                                                else if(floatval($p[$idx]) < floatval($secondLowest) && floatval($p[$idx]) != floatval($lowest))
                                                {
                                                    $secondLowest = floatval($p[$idx]);
                                                }
                                            }
                                            $ttlIdx++;
                                        }
                                        $lowestLinePrice = $lowest;
                                        $lowestLineExtend = $lowestLinePrice;// * floatval($lineQty);
                                        if($lowestLineExtend == null)
                                        {
                                            $lowestLineExtend = 0;
                                        }
                                        if(floatval($temp) == floatval($lowest) && !$lowestFound)
                                        {
                                            $lowestFound = true;
                                            $cpStyle = 'style="background-color:#3399FF;text-align:center;"';
                                        }
                                        else if(floatval($temp) == floatval($secondLowest) && !$secondLowestFound)
                                        {
                                            $secondLowestFound = true;
                                            $cpStyle = 'style="background-color:#B8DBFF;text-align:center;"';
                                        }
                                        $temp = '$' . number_format($temp, 2);
                                    }
                                }
                                        ?>
                                            <td scope="col" <?php echo $cpStyle; ?>><?php echo $temp; ?></td>
                                        <?php
                            }
                                    ?>
                                    <td style="text-align:center;">
                                        <?php 
                            if($lowestLineExtend == 0)
                            {
                                echo '';
                            }
                            else
                            {
                                echo '$' . number_format($lowestLineExtend, 2); 
                                $winningTotal += $lowestLineExtend;
                            }
                            
                                        ?>
                                    </td>
                                    <td style="display:none;">
                                        <input name="cpPrice[]" type="hidden" value="<?php echo number_format($lowestLineExtend, 2); ?>" />
						                <input name="bidwinner[]" type="hidden" value="<?php echo $mainArrayVendorIds[$winningVendorIdx]; ?>" />
                                    </td>
                                    </tr>
                                    <?php
                            $idx++;
                        }
                                    ?>
                                     <tr>
                                        <td colspan="3">Total Bid Prices</td>
                                        <?php
                        //foreach($mainArrayVendorPrices as $prices)
                        //{
                        //    $ttl = 0;
                        //    foreach($prices as $p)
                        //    {
                        //        $ttl += intval($p);
                        //    }
                        //    if($ttl == 0)
                        //    {
                        //        $ttl = '';
                        //    }
                        foreach($columnTotals as $ttl){
                            if($ttl == 0)
                            {
                                $ttl = '';
                            }
                            else
                            {
                                $ttl = '$' . number_format($ttl, 2);
                            }
                                                ?>
                                                <td style="text-align:center;"><?php echo '';//$ttl; ?></td>
                                                <?php
                        }
                                            ?>
                                        <td style="text-align:center;background-color:#3399FF;"><?php echo '$' . number_format($winningTotal, 2); ?></td>
                                    </tr>                                       
                                </table>
                                <div style="float:right;margin:2em 0.5em 0 0;">
                                        <input name="bid" type="hidden" value="<?php echo $bid; ?>" />
	    			                    <input type="submit" value="Award Cherry Picker Vendors" />
                                </div>
                                <!--
                                    <table bgcolor="#FFFFFF" border="1" width="700" cellpadding="5" cellspacing="5">
                                    <th scope="col">Quantity</th>
                                    <th scope="col">Unit(s)</th>
                                    <th scope="col">Description</th>
                                    <th scope="col">Lowest Vendor Prices</th>
                        
                                    <?php  //foreach($items as $item){ ?>
				                    <tr>
					                    <td><?php //echo $item['quantity'];?></td>
					                    <td><?php //echo $item['units']; ?></td>
					                    <td><?php //echo $item['description']; ?></td>
					                    <?php //if(!isset($item['lowest_vendor']['price']) && $item['lowest_vendor']['price'] != 0){ ?>
					                    <td>No Value Was Entered</td>
					                    <?php //} //end if
                        // else{ ?>
					                    <td align="right">
						                    <label for="cpPrice[]"><?php //echo $item['lowest_vendor']['name']; ?></label>
						                    &nbsp;&nbsp;
						                    <input name="cpPrice[]" value="<?php //echo $item['lowest_vendor']['price']; ?>" readonly="readonly" class="cpLowestPrice" />
						                    <input name="bidwinner[]" type="hidden" value="<?php //echo $item['lowest_vendor']['id']; ?>" />
					                    </td>
					                    <?php //} //end if...else ?>
				                    </tr>		    		
	    		                    <?php //}///end for ?>
	    		                    <tr>
	    			                    <input name="bid" type="hidden" value="<?php //echo $bid; ?>" />
	    			                    <td align="right" colspan="4"><input type="submit" value="Award Cherry Picker Vendors" /></td>
	    		                    </tr>
	    	                    </table>
                                -->
	                        </form>
	                    </div>
                        <!-- end cherry picker -->

	                   <?php
                        /*
                         *	TOTAL LOWEST BID MODE
                         */
                        // start table
                        $qlowesttotal = "SELECT * FROM tbl_submissions WHERE sub_bid_id='$bid' AND sub_status = 1 ORDER BY sf_total_price ASC LIMIT 1";
                        $rlowesttotal = mysql_query($qlowesttotal);
                        $lt_subcoid = mysql_result($rlowesttotal,0,"sub_company_id");
                        $qlt2 = "SELECT * FROM `tbl_companies` LEFT JOIN `tbl_submissions` ON company_id = sub_company_id WHERE `company_id` = \"$lt_subcoid\" AND `sub_bid_id` = \"$bid\"";
                        $rlt2 = mysql_query($qlt2);
                        $v_name = mysql_result($rlt2,0,"company_name");
                        $v_id = mysql_result($rlt2,0,"company_id");
                        $v_prices = explode("~", mysql_result($rlt2,0,"bid_unit_prices"));
                        ?>
                        
                        
                        <div class="TabbedPanelsContent">
                            <form name="lowestTotal" id="lowestTotal" action="biducation.php?action=awardbidtest" method="post">
                                <h2>Lowest Total Mode</h2>
                                <h4 style="color:#888888;"><?php echo $priceDescription; ?></h4>
                                <table bgcolor="#FFFFFF" border="1" width="700" cellpadding="5" cellspacing="5">
                                    <th scope="col">Quantity</th>
                                    <th scope="col">Unit(s)</th>
                                    <th scope="col">Description</th>
                                    <th scope="col"><?php echo $lowestTotalPrices[$lowestTotalWinningIdx][1]; ?> Prices</th>
                                    <?php
                        // loop to create table with bid items and qtys
                        $ttl = 0;
                        for($i=0; $i<count($lowestTotalPrices[$lowestTotalWinningIdx][2]); $i++){
                            //$linePrice = floatval($arrayBidQtys[$i]) * floatval($v_prices[$i]);
                            //$dsp = '';
                            //if($linePrice > 0)
                            //{
                            //    $ttl += $linePrice;
                            //    $dsp = '$' . number_format($linePrice, 2);
                            //}
                            $dsp = '$' . number_format($lowestTotalPrices[$lowestTotalWinningIdx][2][$i], 2);
                            echo "<tr>";
                            echo "<td>$arrayBidQtys[$i]</td>";
                            echo "<td>$arrayBidItems[$i]</td>";
                            echo "<td>$arrayBidDescr[$i]</td>";
                            echo '<td style="text-align:center;">' . $dsp . '<input name="bidwinner[]" type="hidden" value="' . $lowestTotalPrices[$lowestTotalWinningIdx][0] . '"/></td>';
                            echo "</tr>";
                        }
                                    ?>
                                    <tr>
                                        <td colspan="3"></td>
                                        <td style="text-align:center;"><?php echo '$' . number_format($lowestTotalPrices[$lowestTotalWinningIdx][3], 2); ?></td>
                                    </tr>
                                    <tr>
                                        <td align="right" colspan="4">
                                        <input type="submit" value="Award Lowest Total Vendor" />
                                        </td>
                                    </tr>
                                </table>
                                
                                <input name="bid" type="hidden" value="<?php echo $bid; ?>" />
                            </form>
                        </div>
                        <!-- end lowest total -->
                        
        
		
                        <!-- start A-Z -->
                        <div class="TabbedPanelsContent">
                        <form name="atoz" id="atoz" action="biducation.php?action=awardbidtest" method="post"><!--award&method=az"-->
                        <h2>A-Z Mode</h2>
                        <h4 style="color:#888888;"><?php echo $priceDescription; ?></h4>
                                                        
                   [/php] 		    
                        [/php]
Quantity Unit(s) Description <?php echo $vn; ?> Total
<?php echo $lineQty;?> <?php echo $item['units']; ?> <?php echo $item['description']; ?>

Hmmm, Tobias, I am at a loss. After writing a few things about the code you posted, I reread what I wrote and it sounds a little harsh. I am sorry, I am not “slamming” the code you posted, but, some of it doesn’t make sense to me. Perhaps I do not see the grand picture clear enough. So, anyways, here is what I wrote. Sorry if it seems hard on the code!

Well, first, this section of code right at the top puts a lot of stress on your server.

$q = "SELECT * FROM `tbl_bids` WHERE `bid_id` = \"$bid\"";
$result=mysql_query($q);
$num=mysql_numrows($result);         
if($num != 0){
for($i=0;$i<$num;$i++){
$bid_name = mysql_result($result,$i,'bid_name');
$bid_contact = mysql_result($result,$i,'bid_contact');
$bid_phone = mysql_result($result,$i,'bid_phone');
$bid_fax = mysql_result($result,$i,'bid_fax');
$bid_email = mysql_result($result,$i,'bid_email');
$bid_address = mysql_result($result,$i,'bid_address');
$bid_address2 = mysql_result($result,$i,'bid_address2');
$bid_city = mysql_result($result,$i,'bid_zip');
$bid_state = mysql_result($result,$i,'bid_state');
$bid_zip = mysql_result($result,$i,'bid_zip');
$bid_attachment = mysql_result($result,$i,'bid_attachment');
echo "$bid_name<br />$bid_contact<br />$bid_phone<br />$bid_fax<br />$bid_email<br />$bid_address<br />$bid_address2<br />$bid_city<br />$bid_state<br />$bid_zip<br />$bid_attachment";

You can do it this way…
[php]
$q = “SELECT * FROM tbl_bids WHERE bid_id = “$bid””;
$result=mysql_query($q);

while ($row = mysql_fetch_assoc($result)) {
   echo $row['bid_name']."<br />".$row['bid_contact']."<br />".$row['bid_phone']."<br />".$row['bid_fax']."<br />".$row['bid_email']."<br />".$row['bid_address']."<br />".$row['bid_address2']."<br />".$row['bid_city']."<br />".$row['bid_state']."<br />".$row['bid_zip']."<br />".$row['bid_attachment'];
}
 mysql_free_result($result);

[/php]
(5 commands instead of 18)
This cuts down the PHP commands drastically and speeds up all processing. All of those MYSQL calls drags the server down. In this manner, you only make two queries. One to select the data, one to format it into a row of data that is linked by ASSOCIATED field names. ( Much easier on the server and on the eye. )
Only showed one sample of how to do it for the first posted routine…

Also, there is a TON of bloated code pulling data from the DB into arrays and then processing “min” commands on them. This should just be done using the query instead. You can select all of the bidder’s, sorting them by minimum bid’s and have the query do all the work for you and then, just load the results into the $row array saving hundreds of processing commands going thru all those loops. Perhaps this was all done a long time ago berfore DB processing became so common?

Now, since I still do not totally understand your application, I guess I need to ask some further questions.
First, it is a bidding system. You have producers of products. They enter starting bids on products or put them up for bidding. Then, you have schools or whatever that make bids on the products. Then, when all the bids are final, you total up the results and process payments and the such. Normally, I would say that as a bid become “final” or is a “winning” bid, it would be posted to the DB. Then, when all the bid’s are “final”, a simple DB query would pull the total of all the “final” bids using the MySQL’s summing options. (When you run a query, you can total col’s and sort by groups such as bidders or producers and then load just the results into an array instead of doing tons of PHP math code!)

Is that layout somewhat close? So, if you need to total up the winning bids, you would do that once all the drop-downs are selected. Who alters the drop-downs? And, when are they posted and by who. I just do not understand your “flow” of your pages. This mess started with a simple question on how to total up a sum of values. Looking at the code, it is hard to say what is what. A lot of this code passes record keeping back an forth. These days, that is seldom done. Normally, you just keep the bid with one small field with the ID of the buyer and seller, just passing two integer’s instead of all those fields. Must easier. If you keep all your bid items, quantities and bids made in the DB, most of the work you have shown can be done with just a few DB Queries. I realize you did not write all this. Anyway, explain the “flow” a little further.

Sorry that I do not understand all that code you posted. It looks like the place to total it all up would be the PHP script where the program goes once all the bids are won. But, I am not sure where that is.

I doubt all this helped. Sounded more like a code-complaint. Sorry! Do you have this online so we could look at the pages and at least have an idea of what code goes with what page?

You are not harsh at all. all of this is great :smiley: . It is live and we have been testing it and the first REAL bids have been coming in. Today at well now it would be yesterday at 3 we had a huge bid come in. And yes you are correct contracters are placing bids on products like PVC pipe and and such from venders and in turn all this makes makes the towns and countys money.

and if you want I can let you look at any part of any of it at any time. I can even let you in the server to see what you think you can do to help stream line this. I can even let you see the bidding process or what ever it takes to get this working correct. I can e-mail you the full on code if need be. as our server is a lil confusing. 50+ folders with sub folders in them. it took me 12 hours and a few phone calls just to find the right stuff that I needed to edit. cause there is so many coppys of the same thing.

the big prob is that there was 11 diff people that had a hand in writing this before I came a long.

WHEW! Now I understand. I just couldn’t understand why some of the things were done the way they did it. I feel that the site could be made much much smaller and much faster, but, it would involve a big rewrite.

(Of course, this is only based on a small amount of code that you posted.) If I could see the site working live, I think I could make more sense of it all. Send me a private message and I will send my email to you so we can talk faster…

Also, the code I posted awhile ago does total up arrays, so I think that would be easy once you know where to stick it… LOL, In mean place the code into the correct file… Almost 2 AM here, off to bed soon!

I will let you see the site running live today when ever

Thanks for all your help so far

Sorry, I had an slight emergency to deal with and have been gone till just now.
I have plans tonight, so will be back to help you in the morning.

Sponsor our Newsletter | Privacy Policy | Terms of Service