Pages

Sunday, January 18, 2015

Integrating

... PHP, MySQL and Javascript is proving to be a bit of an undertaking.

My rainfall project produces a MySQL database with a table of rainfall data for several California cities. I have PHP code that can read it and create a table from it in a browser like so.

Modesto Percent of Normal Rainfall

Date20142013
21-Dec-1421842
22-Dec-1421341
23-Dec-1420940
24-Dec-1420440
25-Dec-1420039
26-Dec-1419738
27-Dec-1419337
28-Dec-1419037
30-Dec-1418335
31-Dec-1417935
01-Jan-1517734
02-Jan-1517334
03-Jan-1517133
04-Jan-1516832
05-Jan-1516532
06-Jan-1516231
07-Jan-1516031
08-Jan-1515730
09-Jan-1515530
10-Jan-1515229
11-Jan-1515029
12-Jan-1514728
13-Jan-1514428
14-Jan-1514227
15-Jan-1514027
16-Jan-1513827
17-Jan-1513626

Graphing this data has proven problematic in PHP, requiring me to learn javascript in order to use the excellent Google Charts library. Javascript, being browser-side, doesn't integrate well with the MySQL on the server. My first guess at solving this problem is to write a PHP script which produces a CSV string of the rainfall data and have the javascript code read that page in as a string. I then parse the CSV into an array and insert it into the graphing library.

Bite-size pieces. It's all going to have to be done in bite-sized pieces. I just wrote the PHP code to make the CSV. Now it's time to take a mental break and watch the Arsenal-ManU game.

2 comments:

  1. Years ago, I wrote a proof of concept set of web pages that embedded JavaScript insode of PPP inside of perl. Debugging that was difficult.

    We went a different direction.

    I know what you mean though, we need a language that can do input output and database queries all at the same time.

    ReplyDelete
  2. I'm glad to hear that my problem isn't simple ignorance. From what I'm reading, jQuery with Ajax is the way to go, using the GET function to return my CSV as a string.

    ReplyDelete