Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:39:59+00:00 2026-06-11T04:39:59+00:00

First off, I’m very new to PHP (and programming in general) and I’m trying

  • 0

First off, I’m very new to PHP (and programming in general) and I’m trying to self learn it in my spare time by developing a gaming site with some custom tools that use php and mysql. So please keep that in mind as you read on.

What I need is a point in the right direction (or a little explanation on what does what) to learn how to properly code a function to do some math on a form for me once the data is sent to POST by the users.

Here’s the background info:

In the database I have a table of “raw materials” that can be converted into varying amounts of 8 different “products”. There is then another table which has those 8 products and their prices.

I have a form set up which automatically generates my Select boxes (SelectList1 thru 11) with this format from a simple query against the Raw Item Names:

<td>
<div align="center">
    <select name="SelectList1">
       <option value=0></option>
       <option value=1>Raw Item 1</option>
       <option value=2>Raw Item 2</option>
       ...
       <option value=47>Raw Item 47</option> //Yes, there is a lot
</div>
</td>

Next to the Select Box is this text input box which people can use to type in the number of each Selected “raw material”. name=productNum1 thru 11

<td>
    <input type="text" size="15" maxlength="10" name="productNum1" id="productNum1">
</td>

That concludes the user form – they select the raw item and then punch in a number for how many they are going to sell.

Now on submit, I have another piece of lengthy code which goes to the database and fetches the needed arrays of both the product price table and the “raw material” table and all it’s various data.

Fetched Price Array Layout:

$pDA = Array (
    [product1] => Array (
        [id] => 1
        [productname] => Product1
        [price] => 599 //whole number used to avoid float precision issues
        )
    .....
    [product8] => Array ( //repeat above values

Fetched Raw Material Array:

$oDA = Array (
    [material1] => Array (
        [id] => 1
        [materialname] => Material1
        [batch] => 100 //Number needed to process
        [product1] => 0 //changes based on material
        [product2] => 0 //changes based on material
        [product3] => 0 //changes based on material
        [product4] => 0 //changes based on material
        [product5] => 0 //changes based on material
        [product6] => 0 //changes based on material
        [product7] => 0 //changes based on material
        [product8] => 0 //changes based on material
        )
    ..... continue all the way down to 
    [material47] => Array ... etc

So that’s all the data. What I need to do now is take the Select box post and have it fetch the appropriate Array data and product numbers if they are greater than 0.

Once it has those and they are stored correctly the math needs to take place against the user submitted “productNum1” value.

For example:

After processing, Rawmaterial1 has 500 of product1 and 250 of product6, and 0 of the rest.
Rawmaterial1 has a batch of 100
User selects Rawmaterial1
User enters 1000 for # of Rawmaterial1

Fetch Array Data against Select Box
Array returns data for Rawmaterial1
    (1000 submitted / 100 Batch) = 10 runs
        10 runs = 5000 of product1
        10 runs = 2500 of product6
            5000 * product1price = value1
            2500 * product2price = value2
$totalvalue = $value1 + $value2

This is where I am lost – I can code to do the math individually by assigning post values to a load of strings & variables as I have before, but I’m positive there is an easier method that I am missing in my lack of understanding.

Thank you to anyone in advance for reading my Beg for Help novel here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:40:01+00:00Added an answer on June 11, 2026 at 4:40 am

    I think you are doing something like this:

    1. Get all data from database
    2. Assign to arrays
    3. Get $_POST data
    4. Match $_POST data against the fetched arrays

    It is more standard to take the $_POST information and query the database with this information (ensuring that you filter the data before you run it in a query to prevent injection).

    So if a user says he is selling 50 units of product 1 and 20 units of product 2, these figures can be used in the database query so you only return the data that you actually want.

    This means that you don’t need to do the matching or math in your code; it should really be done in the SQL if I understand your issue correctly.

    Please feel free to comment if I have not understood your problem correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, a lil about me, i'm very new to GUI programming, especially with
First off im very new to C# im trying to recreate a application i
First off I'm new to owning an android and trying to develop android apps.
First off, I am totally new to PHP, but so far i love the
first off I'm a noob to PHP but here is my problem. I am
First off, I would like to make clear, that I am SUPER NEW TO
First off, a big thanks to the people behind the new boost::geometry library! This
First off, I'm not terribly experienced in XML. I know the very basics of
First off I am pretty new to C, so I probably just have a
First off, I'm pretty new so I hope I hadn't missed anything too trivial.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.