Help - Search - Member List - Calendar
Full Version: arrays
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
ozgur teksin
hi
I have a project to finish in php. I have to send some values and make
calculation through email. Actually I found the solution for sending hidden
values through email. But the solution is just a few items . If there are
alot of items i a screwed. Because i have to write a long listing code. This
doesnt make sense. Here is my code so you can understand what i mean.


a piece of my html code is
<form method="POST" action="estimate.php">
<input type="text" size="2" maxlength="3" name="item_2" class="txt2"><input
type="hidden" name="Weight_2" value="65"><input type="hidden" name="Name_2"
value="Bookshelves, per section"></td>
<td class="txt3">&nbsp;Chair, Arm</td>
<td class="txt3">
<input type="text" size="2" maxlength="3" name="item_3"
class="txt2"><input type="hidden" name="Weight_3" value="60"><input
type="hidden" name="Name_3" value="Chair, Arm"></td>
</tr>
<tr>
<td class="txt3">Chair Rocker (wood)</td>
<td class="txt3">
<input type="text" size="2" maxlength="3" name="item_4"
class="txt2"><input type="hidden" name="Weight_4" value="40"><input
type="hidden" name="Name_4" value="Chair Rocker (wood)"></td>
<td class="txt3">&nbsp;Chair Overstuffed</td>
<td class="txt3">
<input type="text" size="2" maxlength="3" name="item_5"
class="txt2"><input type="hidden" name="Weight_5" value="120"><input
type="hidden" name="Name_5" value="Chair Overstuffed"></td>
</tr>
<tr>
<td class="txt3">Chair Straight</td>
<td class="txt3">
<input type="text" size="2" maxlength="3" name="item_6"
class="txt2"><input type="hidden" name="Weight_6" value="25"><input
type="hidden" name="Name_6" value="Chair Straight"></td>
<td class="txt3">&nbsp;Desk, Small</td>
<td class="txt3">
<input type="button" value="SUBMIT ESTIMATION REQUEST" name="submit">

my php code is ;

<?php
$FTGName_2 = $item_2 * $Weight_2;
$FTGName_3 = $item_3 * $Weight_3;
$FTGName_4 = $item_4 * $Weight_4;
$FTGName_5 = $item_5 * $Weight_5;
$FTGName_6 = $item_6 * $Weight_6;

$FTGtotal = $FTGName_2 + $FTGName_3 + $FTGName_4 + $FTGName_5 + $FTGName_6;

$body = "$Name_2 : $FTGName_2n"
. "$Name_3 : $FTGName_3n"
. "$Name_4 : $FTGName_4n"
. "$Name_5 : $FTGName_5n"
. "$Name_6 : $FTGName_6n"


?>

if there is not alot of item it is fine. But what if i have hundred item.
How am i going to calculate. I use some for loop but i didnt work very well.
Can somebody help me please. I m going crazy over here.

Thanks in advance

Veikko Mkinen
Please do not cross post (send a single message to multiple groups). If
you want to send it to more than one group just send one message with
all the groups listed in the header and set follow-ups to a single
group. See http://home.icomnet.com/support/usenet.shtml

I answered you in alt.php.


-veikko

--
veikko
mail@ .com
makinen

Kimmo Laine
"ozgur teksin" <[Email Removed]> wrote in message
news:[Email Removed]...
QUOTE
hi
I have a project to finish in php. I have to send some values and make
calculation through email. Actually I found the solution for sending
hidden
values through email. But the solution is just a few items . If there are
alot of items i a screwed. Because i have to write a long listing code.
This
doesnt make sense. Here is my code so you can understand what i mean.


a piece of my html code is
<form method="POST" action="estimate.php"
<input type="text" size="2" maxlength="3" name="item_2"
class="txt2"><input
type="hidden" name="Weight_2" value="65"><input type="hidden"
name="Name_2"
value="Bookshelves, per section"></td
<td class="txt3">&nbsp;Chair, Arm</td
<td class="txt3"
<input type="text" size="2" maxlength="3" name="item_3"
class="txt2"><input type="hidden" name="Weight_3" value="60"><input
type="hidden" name="Name_3" value="Chair, Arm"></td
</tr
<tr
<td class="txt3">Chair Rocker (wood)</td
<td class="txt3"
<input type="text" size="2" maxlength="3" name="item_4"
class="txt2"><input type="hidden" name="Weight_4" value="40"><input
type="hidden" name="Name_4" value="Chair Rocker (wood)"></td
<td class="txt3">&nbsp;Chair Overstuffed</td
<td class="txt3"
<input type="text" size="2" maxlength="3" name="item_5"
class="txt2"><input type="hidden" name="Weight_5" value="120"><input
type="hidden" name="Name_5" value="Chair Overstuffed"></td
</tr
<tr
<td class="txt3">Chair Straight</td
<td class="txt3"
<input type="text" size="2" maxlength="3" name="item_6"
class="txt2"><input type="hidden" name="Weight_6" value="25"><input
type="hidden" name="Name_6" value="Chair Straight"></td
<td class="txt3">&nbsp;Desk, Small</td
<td class="txt3"
<input type="button" value="SUBMIT ESTIMATION REQUEST" name="submit"

my php code is ;

<?php
$FTGName_2 = $item_2 * $Weight_2;
$FTGName_3 = $item_3 * $Weight_3;
$FTGName_4 = $item_4 * $Weight_4;
$FTGName_5 = $item_5 * $Weight_5;
$FTGName_6 = $item_6 * $Weight_6;

The above can be also:
$FTGName[2] = $_REQUEST["item_2"] * $_REQUEST["Weight_2"];

And that can be then turned into a loop
for($z=2;$z<6;$z++)
$FTGName[$z] = $_REQUEST["item_$z"] * $_REQUEST["Weight_$z"];

QUOTE
$FTGtotal = $FTGName_2 + $FTGName_3 + $FTGName_4 + $FTGName_5 +
$FTGName_6;

This can be done inside the previous loop:
for($z=2;$z<6;$z++){
$FTGName[$z] = $_REQUEST["item_$z"] * $_REQUEST["Weight_$z"];
$FTGtotal += $FTGName[$z];
}

QUOTE
$body = "$Name_2 : $FTGName_2n"
. "$Name_3 : $FTGName_3n"
. "$Name_4 : $FTGName_4n"
. "$Name_5 : $FTGName_5n"
. "$Name_6 : $FTGName_6n"


This can also be done inside the previous loop:
for($z=2;$z<6;$z++){
$FTGName[$z] = $_REQUEST["item_$z"] * $_REQUEST["Weight_$z"];
$FTGtotal += $FTGName[$z];
$body .= $_REQUEST["name_$z"] . " : " . $FTGName[$z] . "n";
}

So basiclly that's all you need. And by modifying the starting value of $z
(now 2) and the ending value (now 6) you should be able to loop throught
like 100 items, or a thousand. For example for($z=0;$z<100;$z++){...

QUOTE
?

if there is not alot of item it is fine. But what if i have hundred item.
How am i going to calculate. I use some for loop but i didnt work very
well.
Can somebody help me please. I m going crazy over here.

No need to go crazy.

QUOTE
Thanks in advance


no problemo.

--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com

ozgur teksin
Hi guys,

Thanks for your help.

Can anyone tell me what is wrong with this script. Because I couldt send the
values of Name_2 or Name_3 when I submit the form and check the email.
This is just a piece of my html and my php code. Name_2 ....... Name_200.
Thanks again in advance


for example

Name : whatever
Res Phone : 9458943
Email : whatever@whatever
Bus Phone : 9489584
The Total is 230

I would like to get by submission

Name : whatever
Res Phone : 9458943
Email : whatever@whatever
Bus Phone : 9489584
Bookshelves : 130
Chair : 60
Chair Rocker : 40
The Total is 230

Here is my html

<form method="POST" name="EstimationForm" action="estimate.php">
<input type="text" name="GI_name" size="24" class="txt2">
<input type="text" name="GI_resphone" size="24" class="txt2">
<input type="text" name="GI_email" size="24" class="txt2">
<input type="text" name="GI_busphone" size="24" class="txt2">

<input type="text" size="2" maxlength="3" name="item_2" class="txt2"><input
type="hidden" name="Weight_2" value="65">
<input type="hidden" name="Name_2" value="Bookshelves, per section"></td><td
class="txt3">

<input type="text" size="2" maxlength="3" name="item_3" class="txt2"><input
type="hidden" name="Weight_3" value="60">
<input type="hidden" name="Name_3" value="Chair, Arm"></td>

<input type="text" size="2" maxlength="3" name="item_4" class="txt2"><input
type="hidden" name="Weight_4" value="40">
<input type="hidden" name="Name_4" value="Chair Rocker (wood)"></td>


my php script
<?
$FTGGI_name = $_POST['GI_name'];
$FTGGI_resphone = $_POST['GI_resphone'];
$FTGGI_email = $_POST['GI_email'];
$FTGGI_busphone = $_POST['GI_busphone'];
for($i=2;$i<166;$i++){
$FTGName[$i] = $_POST["item_$i"] * $_POST["Weight_$i"];
$FTGtotal += $FTGName[$i];
}
$to = "[Email Removed]";
$subject = "Estimation Request";
$body = "Customer Name : $FTGGI_namen"
. "Customer Residence Phone: $FTGGI_resphonen"
. "Customer Email: $FTGGI_emailn"
. "Customer Business Phone: $FTGGI_busphonen"
for($i=2;$i<166;$i++){
.. "$_POST["name_$i"] . " : " . $FTGName[$i] . "n" ";
}
. "Total is $FTGtotaln";

?>


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.