This is a post that comes in the succession of others posts like "Total price of selected products...".
At this moment I have an array problem named quant that i donīt know if is right and I need you help:
Code that I do at this moment:
PHP Code:
PHP]<?
$sql = "select * from produtos p, tipo_prod t where p.tipo_ID = t.tipo_ID and p.area_ID = 1 and p.active = 'y' and t.tipo_nome = '".$arr["tipo_nome"]."' order by p.prod_ID desc";
$queryl = query($sql) or die ("Query failed: " . mysql_error() . " Actual query: " . $sql);
$contal = mysql_num_rows($queryl);
for ($j=0; $j<$contal;$j++)
{
$arrl = mysql_fetch_array($queryl);
?>
<tr>
<td width="56"><input name="produto[]" type="checkbox" value="<? echo $arrl["prod_ID"]; ?>"></td>
<td width="66" align="left"><img src="<? echo $arrl["imagem"]; ?>" width="60" height="90" border="0" /></td>
<td width="131"><?php echo $arrl["nome"]; ?></td>
<td width="82">Quant.
<input name="quant[]" type="text" id="quant[]" size="1"></td>
<td width="56"><?php echo $arrl["preco"]; ?> *</td>
<td width="63"><?php echo $arrl["descricao"]; ?></td>
</tr>
<tr>
<td colspan="3" class="back04"><img src="images/1X1.gif" alt="" width="1" height="1" /></td>
</tr>
<? } ?> [/PHP]
.
.
.
in another script:
<?php
include("functions.php");
echo $_POST["quant"];
$produto = $_POST["produto"];
$quant= $_POST["quant"];
//$quant = (int) $quant_t;
settype($quant, "integer");
echo $quant;
?>
.
.
.
PHP Code:
PHP Code:<?
if($produto)
{
echo count($produto);
echo count($quant);
echo $quant;
if (count($produto)==count($quant))
{
$total=0;
for ($i=0; $i<count($produto);$i++)
{
$sql = "select * from produtos p, tipo_prod t where p.tipo_ID = t.tipo_ID and p.prod_ID = ".$produto[$i];
$queryl = query($sql) or die ("Query failed: " . mysql_error() . " Actual query: " . $sql);
$arrl = mysql_fetch_array($queryl);
$conta = $arrl["preco"];
echo $produto[$i];
$q = (int) $quant[$i];
echo $q;
if ($q>0)
{
$total_prod = $conta * $q;
}
else
{
echo "A quantidade deste produto é zero";
}



Reply With Quote
Bookmarks