Piotto
11-15-2009, 05:47 PM
Hi people,
I am still working on my catalogue project, and i finally achieved some results that i would like to share.
The theory:
I read data from a db and show it into a form that contains textboxes and checkboxes.
The name of all checkboxes is pickitem[] to make an array out of them.
The value of each checkbox is the $id of the item pulled from the db.
One of the textboxes in the form is the Quantity field, that user can modify changing the default value of 1.
The name of all Quantity textboxes is itemquantity[] to make another array.
So, I can now select some items checking the respective checkboxes.
I will change the Quantity field too.
I submit the form.
In the next page, using the $id that comes as the value of the checkboxes, I pull from the db only the data of the checked items.
So far, so good. Everything works fine.
Problem is the Quantity field.
In the second page I receive only one value of Quantity, the one from the first item of the catalogue. So everything get multiplied by the same amount!
Why? How can I create a relation between the Quantity array and the checked items?
Some code to play with......;)
Catalogue page:
[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:1; } </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];
$itemname = ereg_replace("##semicolon##",";",$itemname);
$itemdescr = ereg_replace("##semicolon##",";",$itemdescr);
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='1'></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='$id'></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]
By the way, the db is just a CSV text db. Doesn't matter now.
Here is the page that receive the stuff...
[CODE]
<?php
include "puszbaza.php";
$file="catalogo1_data.pbf";
if(isset($_POST['calcular']))
{
$verify = $_POST['pickitem'];
$itemquantity = $_POST['itemquantity'];
if(empty($verify))
{
echo("<p><center><b>Please, select something!</center></b></p>\n");
}
else
{
$N = count($verify);
echo "Thanks for choosing $N of our Products!<br><br>";
foreach ($verify as $myid) {
$conn = connect_pb($file);
$result = select_pb($conn, "id","x == $myid","id","DESC");
$number = count_pb($result);
for($i=0;$i< $number;$i++)
{
$id = $result["id"][$i];
$itemname = $result["itemname"][$i];
$itemprice = $result["itemprice"][$i];
$itemname = ereg_replace("##semicolon##",";",$itemname);
$itemdescr = ereg_replace("##semicolon##",";",$itemdescr);
echo $itemname . " - " . $itemprice . " - " . $itemquantity[$i] . " - " . $itemprice * $itemquantity[$i] . "<br>";
}
}
}
}
?>
As I said, everything works but the quantity values...
That's it... today it took me 8 hours to achieve this point... :o
Any help please?
Thanks Alex
I am still working on my catalogue project, and i finally achieved some results that i would like to share.
The theory:
I read data from a db and show it into a form that contains textboxes and checkboxes.
The name of all checkboxes is pickitem[] to make an array out of them.
The value of each checkbox is the $id of the item pulled from the db.
One of the textboxes in the form is the Quantity field, that user can modify changing the default value of 1.
The name of all Quantity textboxes is itemquantity[] to make another array.
So, I can now select some items checking the respective checkboxes.
I will change the Quantity field too.
I submit the form.
In the next page, using the $id that comes as the value of the checkboxes, I pull from the db only the data of the checked items.
So far, so good. Everything works fine.
Problem is the Quantity field.
In the second page I receive only one value of Quantity, the one from the first item of the catalogue. So everything get multiplied by the same amount!
Why? How can I create a relation between the Quantity array and the checked items?
Some code to play with......;)
Catalogue page:
[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:1; } </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];
$itemname = ereg_replace("##semicolon##",";",$itemname);
$itemdescr = ereg_replace("##semicolon##",";",$itemdescr);
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='1'></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='$id'></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]
By the way, the db is just a CSV text db. Doesn't matter now.
Here is the page that receive the stuff...
[CODE]
<?php
include "puszbaza.php";
$file="catalogo1_data.pbf";
if(isset($_POST['calcular']))
{
$verify = $_POST['pickitem'];
$itemquantity = $_POST['itemquantity'];
if(empty($verify))
{
echo("<p><center><b>Please, select something!</center></b></p>\n");
}
else
{
$N = count($verify);
echo "Thanks for choosing $N of our Products!<br><br>";
foreach ($verify as $myid) {
$conn = connect_pb($file);
$result = select_pb($conn, "id","x == $myid","id","DESC");
$number = count_pb($result);
for($i=0;$i< $number;$i++)
{
$id = $result["id"][$i];
$itemname = $result["itemname"][$i];
$itemprice = $result["itemprice"][$i];
$itemname = ereg_replace("##semicolon##",";",$itemname);
$itemdescr = ereg_replace("##semicolon##",";",$itemdescr);
echo $itemname . " - " . $itemprice . " - " . $itemquantity[$i] . " - " . $itemprice * $itemquantity[$i] . "<br>";
}
}
}
}
?>
As I said, everything works but the quantity values...
That's it... today it took me 8 hours to achieve this point... :o
Any help please?
Thanks Alex