Results 1 to 4 of 4

Thread: Total price of selected products...

  1. #1
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Total price of selected products...

    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:

    PHP Code:
    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 />";
                                
                                
                            } 

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    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.

  3. #3
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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&#180;t know sure what to do!!! It&#180;s similar to the checkboxes?? How can correspond to a selected checkbox??

    Thanks for all!!!

  4. #4
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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&#180;t know sure what to do!!! It&#180;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"];



    PHP Code:
    <?  
                            
    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&#180;s - Very Hot - 4
    T-Shirt&#180;s - Very Hot - 0
    T-Shirt&#180;s - Very Hot - 0

    1 product selected with amount of 1. There are 3 products registered.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •