sheriff Posted May 22, 2007 Share Posted May 22, 2007 Hi all. I have a little problem. I have this code: <table border="0" cellpadding="1" cellspacing="1"> <?php if(isset($_POST)){ if(count($_POST['check'])){ $list_selected = ""; foreach($_POST['check'] as $key => $ids){ $list_selected .= $ids .","; } $list_selected = substr($list_selected,0,strlen($list_selected)-1); // This will give ur selected ids like this 100,203,125,123 }else{ $list_selected = "-1"; } } $query = "select * from products WHERE pr_id IN (".$list_selected.")"; $result = mysql_query($query); $count = mysql_num_rows($result); $color1 = "#FF9900"; $color2 = "#CCCCCC"; $row_count = 0; ?> <center><br><span class="cb_text">Oferta Produse</span><br><br> <table align="center" bgcolor="#475558" cellpadding="1" cellspacing="1" width="78%"> <tr> <td width="50" bgcolor="#475558" align="center"><span class="cb_text">Code</span> <td width="100" bgcolor="#475558" align="center"><span class="cb_text">Name</span> <td width="200" bgcolor="#475558" align="center"><span class="cb_text">Description</span> <td width="50" bgcolor="#475558" align="center"><span class="cb_text">Price</span> </tr> <?php while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; $id = $row['pr_id']; $code = $row['pr_code']; $name = $row['pr_name']; $desc = $row['pr_desc']; $price = $row['pr_price']; ?> <tr> <td align="left" bgcolor="<?php echo $row_color; ?>"> <?php echo $code; ?></td> <td align="left" bgcolor="<?php echo $row_color; ?>"> <?php echo $name; ?></td> <td align="left" bgcolor="<?php echo $row_color; ?>"> <?php echo $desc; ?></td> <td align="right" bgcolor="<?php echo $row_color; ?>"><?php echo $price; ?> RON </td> </tr> <?php $row_count++; } ?> <tr> <td colspan="3" align="right" bgcolor="<?php echo $row_color; ?>"><strong>Total</strong> <td bgcolor="<?php echo $row_color; ?>"><?php echo [b]$total= ?????[/b]; ?> </table> so .. how can I calculate the whole components price ? Thanks for help ! Quote Link to comment https://forums.phpfreaks.com/topic/52450-solved-price-calc/ Share on other sites More sharing options...
kathas Posted May 22, 2007 Share Posted May 22, 2007 <table border="0" cellpadding="1" cellspacing="1"> <?php if(isset($_POST)){ if(count($_POST['check'])){ $list_selected = ""; foreach($_POST['check'] as $key => $ids){ $list_selected .= $ids .","; } $list_selected = substr($list_selected,0,strlen($list_selected)-1); // This will give ur selected ids like this 100,203,125,123 }else{ $list_selected = "-1"; } } $query = "select * from products WHERE pr_id IN (".$list_selected.")"; $result = mysql_query($query); $count = mysql_num_rows($result); $color1 = "#FF9900"; $color2 = "#CCCCCC"; $row_count = 0; ?> <center><br><span class="cb_text">Oferta Produse</span><br><br> <table align="center" bgcolor="#475558" cellpadding="1" cellspacing="1" width="78%"> <tr> <td width="50" bgcolor="#475558" align="center"><span class="cb_text">Code</span> <td width="100" bgcolor="#475558" align="center"><span class="cb_text">Name</span> <td width="200" bgcolor="#475558" align="center"><span class="cb_text">Description</span> <td width="50" bgcolor="#475558" align="center"><span class="cb_text">Price</span> </tr> <?php $total = 0; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; $id = $row['pr_id']; $code = $row['pr_code']; $name = $row['pr_name']; $desc = $row['pr_desc']; $price = $row['pr_price']; $total += $row['pr_price']; ?> <tr> <td align="left" bgcolor="<?php echo $row_color; ?>"> <?php echo $code; ?></td> <td align="left" bgcolor="<?php echo $row_color; ?>"> <?php echo $name; ?></td> <td align="left" bgcolor="<?php echo $row_color; ?>"> <?php echo $desc; ?></td> <td align="right" bgcolor="<?php echo $row_color; ?>"><?php echo $price; ?> RON </td> </tr> <?php $row_count++; } ?> <tr> <td colspan="3" align="right" bgcolor="<?php echo $row_color; ?>"><strong>Total</strong> <td bgcolor="<?php echo $row_color; ?>"><?php echo [b]$total= ?????[/b]; ?> </table> In the end of the loop you'll have your total price... Quote Link to comment https://forums.phpfreaks.com/topic/52450-solved-price-calc/#findComment-258797 Share on other sites More sharing options...
sheriff Posted May 22, 2007 Author Share Posted May 22, 2007 thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/52450-solved-price-calc/#findComment-258805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.