Jump to content

[SOLVED] Basic Math Script Needed


jeda

Recommended Posts

Hi everyone,

 

I'm brand new to the forums and have already gained incredible amounts of insight into php coding from reading other forum posts. I'm not much of a developer; I only know enough php to get into trouble, but I'm enjoying the learning process.

 

I'm hoping that someone can help me out with a basic script or some pointers for writing a script. Here's what I need:

 

I have an html form that asks users to consider situations and rank how likely they would be to fall asleep in that situation. For record-keeping purposes, the results are recorded with a full description that includes both letters and numbers. For instance in situation 1, if the user picks "5 - Very Likely to Fall Asleep" then that's exactly what is saved as the value for that form item. When the form is processed, all responses are thrown into an array and saved to the database as a single record (like "1 - unlikely to fall asleep, 5- very likely to fall asleep, etc.).

 

This is set and can't be changed; however, I now need a piece of code that takes the array that holds all the info, strips out ALL letters, spaces, and dashes (in other words takes out everything but the numbers), and adds all the numbers together. The result of the script should be the sum of the numbers.

 

Please let me know if I can clarify this at all. Thanks and look forward to any pointers you can offer!

 

John

 

 

Link to comment
Share on other sites

I have an html form that asks users to consider situations and rank how likely they would be to fall asleep in that situation. For record-keeping purposes, the results are recorded with a full description that includes both letters and numbers. For instance in situation 1, if the user picks "5 - Very Likely to Fall Asleep" then that's exactly what is saved as the value for that form item. When the form is processed, all responses are thrown into an array and saved to the database as a single record (like "1 - unlikely to fall asleep, 5- very likely to fall asleep, etc.).

 

That is overall a bad idea. A field in a database should only contain one element only. Look into database normalization.

Link to comment
Share on other sites

Excellent help guys! I very much appreciate you both taking the time to respond.

 

I'll try the code sample garethp provided this weekend.

 

Daniel0, thanks for the link; I'm very new to systems administration, and it's more of a hobby. Database normalization is not something I was familiar with. I'm going to study the topic and attempt to implement normalization this weekend.

 

Regards!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.