I have the following code to create an array from a column in a MySQL table:
$BCM = array();
while($BCMrow = mysql_fetch_array($allanswers)){
$BCM[] = $BCMrow['BCM'];
}
$BCMrisk = max($BCM);
This looks in the recordset table and pulls the data from each row for the column titled BCM. Then it looks to see which is the highest number. This works fine, but I need to do this for another 10 columns and when I just repeat that code only the first one works.
Any ideas how to fix this?
Edit: Thanks everyone, i went with JBRTRND-DEV's suggestion. It is pretty similar to most of the other ones and works fine. I just needed a quick one to work now, but I will look into using MySQL itself to make it, and into PDO stuff. I'm just starting out with php/mysql stuff. cheers
SELECT MAX(BCM) FROM your_table
. It will be much faster. – Ventus May 24 '12 at 7:58mysql_*
functions. They are no longer maintained and community has begun the deprecation process . Instead you should learn about prepared statements and use either PDO or MySQLi. If you cannot decide, this article will help to choose. If you care to learn, here is a quite good PDO-related tutorial. – tereško May 24 '12 at 8:41