Forum Moderators: coopster

Message Too Old, No Replies

Creating a PHP array from a MySQL query

         

Ewan

6:00 pm on Oct 31, 2007 (gmt 0)

10+ Year Member



Hi all,

I've got a MySQL database which stores monthly records from a weather station. I want to display info from this on a web page. Some data is already displayed as graphs but I want to add some trivia based on the current month.

The query to get the data is

SELECT Year, Rain FROM historical_data WHERE Month = '$current_month' ORDER By Rain DESC LIMIT 3

Fields in the DB are Year, Month, MaxTemp, MinTemp, Rain

Results of the query would be:
Year Rain
===========
year1 rain1
year2 rain2
year3 rain3

I want to show the top 3 records, laid out, eg:

"The wettest <current_month> was in <year1> when <Rain1>mm fell, followed by <year2> (<Rain2>mm) and <year3> (<rain3>mm)."

and not as a table, which would have been easier of course!

How do I put the data returned from the query into a PHP array so that I can display the data as desired?

I've experimented with while and for loops but without success.

Thanks.

PHP_Chimp

6:04 pm on Oct 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[uk2.php.net...]
will get your results in the form of an array.

Ewan

9:25 pm on Oct 31, 2007 (gmt 0)

10+ Year Member



Thanks for that - I found a function in the comments that works a treat!