samoht Posted September 11, 2007 Share Posted September 11, 2007 hello all, I have a function that retrieves multiple prices for a product. I have multiple prices because - in my store each client can have a special price code - and there is also a default ClientPriceCode which is the same as standard retail pricing. I also have a table called "pricecodeprice" that contains fators for each type of PriceCode and ClientPriceCode e.g. PriceCode ClientPriceCode RetailFactor SellFactor A1 R1 2 1.87 A1 W1 1.2 1.2 etc. Now I would like to make my function take the $cost variable and calculate the retail and the sell price for the product - for each client type (or ClientPriceCode) here is my function so far: <?php function get_pprice($pid/*,$pr,$cost*/) { $ProductId = $pid; $sql = dbQuery(" SELECT PriceRetail, PriceSell, PriceHold, Cost, ClientPriceCode, ProductPriceId FROM productprice WHERE ProductId ='$ProductId' "); while($row = dbFetchAssoc($sql)) { $rows[] = $row; } return $rows; } and here is my form: <?php $sql = dbQuery("SELECT PriceCode, Name FROM pricecode ORDER BY PriceCode"); $PriceRetail = $row_rsProduct['PriceRetail']; $Cost = $row_rsProduct['Cost']; while($row = dbFetchAssoc($sql)) { ?><option value="<?php echo $row['PriceCode'];?>" <?php if($row['PriceCode'] == $row_rsProduct['PriceCode']){echo 'selected';}?>><?php echo $row['PriceCode']."|".$row['Name'];?></option><?php } ?> </select></td> <td><input size="7" name="Cost" type="text" id="Cost" style="text-align:right" value="<?php echo $Cost;?>"></td> <td><input size="7" name="PriceRetail" type="text" id="PriceRetail" style="text-align:right" value="<?php echo $PriceRetail;?>"></td> <td><form name="calc"><a class="calc" style="cursor:pointer" onClick="">Recalc prices</a></form></td> </tr> <tr> <td> </td> </tr> <tr> <td>Client</td> <td><span class="errors">*</span>Sell</td> <td><span class="errors">*</span>Hold</td> </tr> <tr> <td><?php $pprice = get_pprice($ProductId/*,$PriceRetail, $Cost*/); for($n = 0; $n < $nClients; $n++) { echo "\n\t<tr class=\"d".($n & 1)."\">\n\t"; if($pprice[$n]['ClientPriceCode']=='R1') { $q = dbQuery("SELECT ShortName FROM clientpricecode WHERE ClientPriceCode = 'R1'"); $r = dbFetchAssoc($q); extract($r); echo "<td><input name=\"ClientPriceCode[$n]\" type=\"hidden\" id=\"ClientPriceCode\" value=\"".$pprice[$n]['ClientPriceCode']."\">$ShortName</td>"; }else { $pc = $pprice[$n]['ClientPriceCode']; $q = dbQuery("SELECT ShortName FROM clientpricecode WHERE ClientPriceCode = '$pc'"); $row = dbFetchAssoc($q); extract($row); echo "<td><input name=\"ClientPriceCode[$n]\" type=\"hidden\" id=\"ClientPriceCode\" value=\"".$pprice[$n]['ClientPriceCode']."\">$ShortName</td>"; } echo "<td><input size=\"7\" name=\"PriceSell[$n]\" type=\"text\" id=\"PriceSell\" style=\"text-align:right\" value=\"".$pprice[$n]['PriceSell']. "\"></td>"; echo "<td><input size=\"7\" name=\"PriceHold[$n]\" type=\"text\" id=\"PriceHold\" style=\"text-align:right\" value=\"".$pprice[$n]['PriceHold']. "\"></td>"; echo "</tr>"; } ?></td> hopefully that makes sense. Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/68887-help-wfunction-get-and-calc-fields/ Share on other sites More sharing options...
samoht Posted September 12, 2007 Author Share Posted September 12, 2007 here is a screen shot of my form and my attempt @ modifying my function: <?php function get_pprice($pid,$pc,$cost) { $ProductId = $pid; $sql = dbQuery(" SELECT PriceRetail, PriceSell, PriceHold, Cost, ClientPriceCode, ProductPriceId FROM productprice WHERE ProductId ='$ProductId' "); $row = dbFetchAssoc($sql); if($cost = $row['Cost']) { mysql_data_seek($sql,0); while($row = dbFetchAssoc($sql)) { $rows[] = $row; } return $rows; }else { $sql = dbQuery(" SELECT RetailFactor, SellFactor FROM pricecodeprice WHERE PriceCode = '$pc' "); while($row = dbFetchAssoc($sql)) { $rows[] = $cost * $row['RetailFactor']. $cost * $row['SellFactor']; } return $rows; } } but I am not sure how to get the button to pass this info to my function - or update my form?? any ideas?? Thanks Link to comment https://forums.phpfreaks.com/topic/68887-help-wfunction-get-and-calc-fields/#findComment-346959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.