Log in

View Full Version : Second approach to catalogue by email



Piotto
11-14-2009, 07:20 PM
Hi everybody!

I have a form in a catalogue page that is populated by a flat DB and has checkboxes.

In order to send data from the catalogue page to another php page i am using the checkboxes value, that (in my code... :rolleyes:) contains the different values for product name, unit price and quantity separated by me with a "|" that come straight from the db.

After submit, in the next page i count and echo the value of the checkbox of each product selected from the catalogue and i sort out (splitted by "|") the different fields.

Now, I would like to be able to let the user changes the quantity field in the first page and send the new value along with the actual form, inside the checkbox value, to the other page, doing a calculation before sending {like subtotal of each product (price * the new inputted quantity)}. The initial value stored in the db is 1.

After connecting to the db I have this code in the first page:

[CODE]
... connect to db and get data...
...$itemid
...$itemname
...$itemphoto
...$itemdescr
...$itemprice
...$itemquantity etc ...

$subtotal = $itemprice * $itemquantity;
echo"
<tr><td align='center' height='25' valign='top'>
<input readonly type='text' STYLE='text-align:center;border=0;' name='itemname' size='25' value='$itemname'>
<input type='text' STYLE=text-align:center;background:#C0FFC0; name='itemquantity' size='2' value='$itemquantity'></td>

<td align='center' height='25' valign='top'>
<img src='$itemphoto' name='itemphoto' border='1'></td>

<td align='center' width='200' valign='top'>
<p align='justify' style='font-family:verdana; font-size:11px;'>$itemdescr</p></td>

<td align='center' height='25' valign='top'>
<input readonly type='text' STYLE='text-align:center;border=0;' name='itemprice' size='12' value='$itemprice Mts.'></td>

<td align='center' height='25' valign='top'>
<input type='checkbox' name='pickitem[]' value='$itemname|$itemprice|$itemquantity|$subtotal<br>'></td>

</tr><tr><td height='25' align='center' colspan='6'><hr size='3' color='#000080'></td></tr></center>
";
}
echo "</table><br><input type='submit' value='Calcular Cotação' name='calcular'></form></body></html>";


Now, no matter what i write in the quantity textbox, the result on the other page is still 1.

How can i enable the new value, inputted by the user to go along with the checkbox value and replace the value 1 from the db???

Anyway, there is another way to send the values of the selected products in another page without putting variables into the value field of the checkboxes?

thks (tired and with eyes burning.....) :confused:

JShor
11-15-2009, 12:03 AM
Incedentally, I am Portuguese too. Can you post the full php code to this script? I don't think it's the value of the checkbox, it's probably the explosion of the string.

Piotto
11-15-2009, 04:38 AM
Bom dia Jshor and thanks for the reply. Here it is the code of the page to show the catalogue. I am using puszbaza to manage the db.

[code]

<?
include "puszbaza.php";

$file="catalogo1_data.pbf";

echo"
<html>
<head>
<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>
<META HTTP-EQUIV='Expires' CONTENT='-1'>
<style type='text/css'> input { border:0; } </style>
</head>
<body style='font-family:verdana; font-size:16px;'>
<noscript><meta http-equiv='refresh' content='0;no_javascript_page.html'></noscript>
<center><br><b>Seja bem vindo ao Catalogo 1! Seleccione os Produtos que mais deseja<br>e carregue no botao ao fundo desta pagina para calcular a sua cotacao.</b><br><BR><hr width=664 size=4><BR></center>
<center><table border=0 bordercolor='#000080' cellspacing='4' cellpadding='4'>
<form name='catalogo1' method='POST' action='catalogo1_cotacao.php'>
";

$conn = connect_pb($file);
$result = select_pb($conn, "id","x > -1","id","DESC");
$number = count_pb($result);

for($i=0;$i< $number;$i++)
{
$id = $result["id"][$i];
$itemname = $result["itemname"][$i];
$itemdescr = $result["itemdescr"][$i];
$itemphoto = $result["itemphoto"][$i];
$itemprice = $result["itemprice"][$i];
$itemquantity = $result["itemquantity"][$i];

$itemname = ereg_replace("##semicolon##",";",$itemname);
$itemdescr = ereg_replace("##semicolon##",";",$itemdescr);



$subtotal = $itemprice * $itemquantity;
echo"
<tr><td align='center' height='25' valign='top'>
<input readonly type='text' STYLE='text-align:center;border=0;' name='itemname' size='25' value='$itemname'>
<input type='text' STYLE=text-align:center;background:#C0FFC0; name='itemquantity' size='2' value='$itemquantity'></td>

<td align='center' height='25' valign='top'>
<img src='$itemphoto' name='itemphoto' border='1'></td>

<td align='center' width='200' valign='top'>
<p align='justify' style='font-family:verdana; font-size:11px;'>$itemdescr</p></td>

<td align='center' height='25' valign='top'>
<input readonly type='text' STYLE='text-align:center;border=0;' name='itemprice' size='12' value='$itemprice Mts.'></td>

<td align='center' height='25' valign='top'>
<input type='checkbox' name='pickitem[]' value='$itemname|$itemprice|$itemquantity|$subtotal<br>'></td>

</tr><tr><td height='25' align='center' colspan='6'><hr size='3' color='#000080'></td></tr></center>
";
}
echo "</table><br><input type='submit' value='Calcular Cotação' name='calcular'></form><br><br></body></html>";
?>
[code]

I can retrieve all the fields from the db without a problem and i can see the results on the page.

Problem starts when i send the selected products to the other page.

If i send without changing the quantity it works, but i need user to be able to change the quantity field ($itemquantity is 1 from the db) to another value and use this new entered value to calculate the subtotal in the same page before submitting.

On the other page i will receive something like this

Produto BlaBla|150.00|1|150.00 but i would like to receive this too

Produto BlaBla|150.00|2|300.00 or

Produto BlaBla|150.00|4|600.00 etc.

Percebeste? Tou meio confuso...

Thank

Alex Piotto