PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have records in MySQL database with text like this:
- Good job, 7
- Beautiful lines, an 8
I would like to filter the text with php so only numbers are left. I will show the numbers behind the post as rating. After that I would like to calculate the average of all ratings and save it in a mysql record behind the subject rated.
I have got the following code which shows only the numbers, but I do not know how to calculate the average and put it in a record. Anyone any idea? Is the question clear?[/text]
For an average you need to collect all the numeric values, add them together and divide them by die amount of numbers. You can add the value retrieved from the $number array to another array. Once you have an array with all the numbers you can use count($array) to get the amount of items, and array_sum($array) to get the sum of all the items in the array.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering