PHP Development Issue - the sequel

Posted on 2006-03-25
Last Modified: 2006-11-18
I have this code in place to define the quantity function (thx Brian:)...

$qty_string = "<input type=\"text\" size=\"2\" name=\"qty[]\" style=\"font-family: verdana; font-size: 8pt\" value=\"";

// Item 1
$qty = $_POST["qty"][0];                  // Quantity after Update
$with_disc01 = round( (($price01*(round($discount01/100, 2)))-$price01), 2);
$ext_npl01 = ($price01*$qty);
$ext_inst01 = ($inst01*$qty);
$ext_maint01 = ($maint01*$qty);
$ext_usc01 = ($cost01*$qty);
// Item 2
$qty = $_POST["qty"][1];                  // Quantity after Update
$with_disc02 = round( (($price02*(round($discount02/100, 2)))-$price02), 2);
$ext_npl02 = ($price02*$qty);
$ext_inst02 = ($inst02*$qty);
$ext_maint02 = ($maint02*$qty);
$ext_usc02 = ($cost02*$qty);
// There will be a total of 64 Items, this is just 2 of them

So now I am working on creating totals and am looking for a way to use the existing quantities specified by the user, per item, to create them.  I have tried a few different ways, but being a n00b I'm not having much luck.  Here's an example of what I have tried...

$x_ext_npl = (($price01*$qty_string . $_POST["qty"][0])+($price02*$qty_string . $_POST["qty"][1])+($price03*$qty_string . $_POST["qty"][2]));
$x_ext_inst = (($inst01*$qty_string . $_POST["qty"][0])+($inst02*$qty_string . $_POST["qty"][1])+($inst03*$qty_string . $_POST["qty"][2]));
$x_ext_maint = (($maint01*$qty_string . $_POST["qty"][0])+($maint02*$qty_string . $_POST["qty"][1])+($maint03*$qty_string . $_POST["qty"][2]));
$x_ext_usc = (($cost01*$qty_string . $_POST["qty"][0])+($cost02*$qty_string . $_POST["qty"][1])+($cost03*$qty_string . $_POST["qty"][2]));
$x_ext_disc = (($with_disc01*$qty_string . $_POST["qty"][0])+($with_disc02*$qty_string . $_POST["qty"][1])+($with_disc03*$qty_string . $_POST["qty"][2]));

Welll, it didn't work :)  Anyone have any ideas?  thanks for the help.
Question by:mikemaner
    LVL 15

    Accepted Solution

    Is it just me, or are you trying to multiple a numeric value with a string? :)  Try this instead:

    $x_ext_npl = (($price01*$_POST["qty"][0])+($price02*$_POST["qty"][1])+($price03*$_POST["qty"][2]));
    LVL 15

    Expert Comment

    So the whole thing would look like this:

    $x_ext_npl = (($price01*$_POST["qty"][0])+($price02*$_POST["qty"][1])+($price03*$_POST["qty"][2]));
    $x_ext_npl = (($inst01*$_POST["qty"][0])+($inst02*$_POST["qty"][1])+($inst03*$_POST["qty"][2]));
    $x_ext_npl = (($maint01*$_POST["qty"][0])+($maint02*$_POST["qty"][1])+($maint03*$_POST["qty"][2]));
    $x_ext_npl = (($cost01*$_POST["qty"][0])+($cost02*$_POST["qty"][1])+($cost03*$_POST["qty"][2]));
    $x_ext_npl = (($with_disc01*$_POST["qty"][0])+($with_disc02*$_POST["qty"][1])+($with_disc03*$_POST["qty"][2]));

    Author Comment

    That was it, thanks m8, I am still a bit confused by syntax at this point.  I 'AM' learning though :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now