Inner Joint to joint 2 tables in cart

Discussion in 'PHP' started by afonseca, May 14, 2008.

  1. #1
    Hi all!

    I'm facing a situation that is a little up my knowledge.
    I have a cart (see code below) in a ecommerce site that prints the number of itens/REF/Products name/Packing/Unit price/sub_total.
    My database is divided in 2 tables (one for the products name and other for the REFs).
    I want to ad in the printed results the correspondent description that I have in the table with the REFs.
    like this:

    number of itens/REF/Products name/PRODUCT DESCRIPTION/Packing/Unit price/sub_total.
    I think I must use Inner Joint but don't know much about it!
    Any one can help me with this?
    Hope that I made my self clear. Thanks in advanced.

    António

    <?php

    while($row = mysql_fetch_array($result))
    {
    $id=$row['itemId'];
    $qtd=$row['qty'];
    $preco=$row['euro'];
    $preco_desc=$row['preco_desc'];
    $cod=$row['codigo'];
    $idprd=$row['produto'];
    $qry = mysql_query("select * from produto where id = $idprd ");
    $campos = mysql_fetch_array($qry);

    // Increment the total cost of all items
    if ($preco_desc<>"" and $row['promocao']==1){
    $preco = str_replace(",",".",$preco_desc);
    }
    else{
    $preco = str_replace(",",".",$preco);
    }

    $Subtotal=floatval($preco)*$qtd;
    $totalCost += floatval($preco)*$qtd;
    $Subtotal=str_replace(".",",",$Subtotal);

    //@mysql_query("insert into cart (cod) values(sdsdf) where cookieId = '" . GetCartId() . "' and itemId = $id");
    @mysql_query("update cart set preco = '$Subtotal' where cookieId = '" . GetCartId() . "' and itemId = $id");

    ?>
    <tr>
    <td width="12%" height="25"><div align="left"><font face="verdana" size="1" color="black">
    &nbsp;
    <?php $id=$row['itemId'];?>
    <?php echo $row["qty"]; ?> </font> </div></td>
    <td ><div align="left"><font face="verdana" size="1" color="black"> <?php echo $row['codigo']; ?> </font> </div></td>
    <td width="33%" height="25"><div align="left"><font face="verdana" size="1" color="black"><?
    //print"<a href='detalhe_prod.php?ler=$campos[id]&cod_cat=$campos[id_titulo]'> $campos[produto]</a>"
    echo $campos['produto'];
    ?></font> </div></td>
    <td width="14%" height="25"><div align="left"><font face="verdana" size="1" color="black"><?php echo $row['empacotamento']; ?> </font> </div></td>
    <td width="14%"><div align="left"><font face="verdana" size="1" color="black"> &euro;<?php if ($row['preco_desc']<>"" and $row['promocao']==1){
    echo $row['preco_desc']; }
    else{
    echo $row['euro'];
    }
    ?>
    </font> </div></td>
    <td height="25"><div align="left"><font face="verdana" size="1" color="black"> &euro;<?php echo $Subtotal; ?> </font> </div>
    <div align="center"><font face="verdana" size="1" color="black"> <a href="cart.php?action=remove_item&amp;id=<?php echo $row['itemId']; ?>"></a> </font> </div></td>
    </tr>
    <?php
    }

    // Display the total
    ?>
     
    afonseca, May 14, 2008 IP