View Full Version : Total price of selected products...
pavmoxo
08-09-2006, 10:56 AM
Hi!!
What can I do for obtain a total price of selected products with checkboxes.
I tried with the next piece of code but I don't know how to obtain the final result of the order:
foreach ($produto as $p)
{
echo $p."<br />";
$sql = "select preco from produtos where nome = '".$p."'";
$queryl = query($sql) or die ("Query failed: " . mysql_error() . " Actual query: " . $sql);
$arrl = mysql_fetch_array($queryl);
$conta = $arrl["preco"];
echo $conta."<br />";
}
blm126
08-09-2006, 04:01 PM
query() should be mysql_query first of all. Also you need a database connection to do that. And I don't see how that code is even close to dealing with check boxes. Do a google search for a PHP tutorial.
pavmoxo
08-09-2006, 04:09 PM
Thanks but someone already helps me!!
But at this moment I wan't a field to insert a amount of a product and I wan't to show the total price of the product. I don´t know sure what to do!!! It´s similar to the checkboxes?? How can correspond to a selected checkbox??
Thanks for all!!!
pavmoxo
08-10-2006, 08:54 AM
Thanks but someone already helps me!!
But at this moment I wan't a field to insert a amount of a product and I wan't to show the total price of the product. I don´t know sure what to do!!! It´s similar to the checkboxes?? How can correspond to a selected checkbox??
Thanks for all!!!
Hello!! Can you help me with this??
Code
<input name="produto[]" type="checkbox" value="<? echo $arrl["nome"]; ?>">
...
<input name="quant[]" type="text" size="1">
$produto = $_POST["produto"];
$quant = $_POST["quant"];
<?
if($produto)
{
foreach ($produto as $p)
{
$sql = "select * from produtos p, tipo_prod t where p.tipo_ID = t.tipo_ID and p.nome = '".$p."'";
$queryl = query($sql) or die ("Query failed: " . mysql_error() . " Actual query: " . $sql);
$arrl = mysql_fetch_array($queryl);
$conta = $arrl["preco"];
foreach ($quant as $q)
{
$total_prod = $conta * $q;
echo $arrl["tipo_nome"]." - ".$p." - ".$total_prod."<br />";
}
//echo $conta."<br />";
$total[] = $conta;
}
//echo "Total: ".array_sum($total);
}
else
{
echo "<script>alert('Para realizar uma encomenda necessita de escolher pelo menos um produto');</script>";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=mag_order_1.php\">";
}
?>
An Output:
T-Shirt´s - Very Hot - 4
T-Shirt´s - Very Hot - 0
T-Shirt´s - Very Hot - 0
1 product selected with amount of 1. There are 3 products registered.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.