Page 1 of 2
Display data from SQL in a table on your website
Posted: Thu 04 Feb 2010 11:50 pm
by daj
A number of people have asked how I do this on my site...
http://www.grantownweather.co.uk/historic/historic.php
Basically I am reading my dayfile.txt which I have stored in an SQL database on my webserver (see my other
post on this). I then extract this data from SQL using PHP and show it in a table on my web pages.
There is a lot involved in doing this and many files (several javascript, styles sheets, images, PHP) It's a complicated process so is not for a beginner.
You need to edit dbconfig.php and look (and edit) historic.php, which calls read_dayfile.php (nothing needs editing in there as I have done all the work)
You can download all the files needed here.....
http://www.grantownweather.co.uk/historic/DataTable.zip I think I have included everything!
Good luck
Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 8:14 am
by nitrx
Great I just posted mine

, but I think yours is more sophisticated something to play this weekend
Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 9:27 am
by nitrx
In the dbconfig.php a wrong table is requested
the name of the SQL table holding the dayfile
$table_name="dayfile";
?>
I've changed the dayfile to Dayfile because thats the table where de data are stored (I got empty fields with the lowercase)
Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 9:31 am
by daj
The name of the table is whatever you called it when you imported it, so if yours is "Dayfile" then that is what this setting must be, whereas mine is actually called something complete different

Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 9:35 am
by nitrx
Yep thats no surprise for me

Well I need coffee right now
Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 9:37 am
by daj
It's not the weekend yet, so why are you playing with this? LOL
You said you would play with it at the weekend

Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 9:49 am
by nitrx
I planned a trip to Australia it's weekend over there

Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 5:15 pm
by n9mfk
Hi All,
were do i change from c deg to f deg
http://www.n9mfk.com/historic/
Thanks Beau
Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 6:10 pm
by nitrx
You already diid it I suppose ?
Re: Display data from SQL in a table on your website
Posted: Fri 05 Feb 2010 7:30 pm
by n9mfk
Hi Ron,
I found an had delete to post but it did not delete
Beau
Re: Display data from SQL in a table on your website
Posted: Mon 08 Feb 2010 12:58 am
by GraemeT
Hi David.
I've implemented your excellent MySQL history table with a fair degree of success.
Two points are worth a mention.
The first, regarding the 'colnames' definition. Is there any alternative to using <br/> to insert a line-feed in those headings which require two lines?
The xhtml spec says that <br/> isn't allowed. Not that it matters much to most browsers, though.
My second comment relates to dayfile.txt.
Lines in dayfile.txt since the Cumulus release which added 'Highest Average Wind Speed' and 'Time of Highest Average Wind Speed' are longer by 2 values.
This caused MySQL v5.1.43 to only use the most recent (longer) lines and then report errors for all the rest, having been told to expect 18 values, but only getting 16).
I added 2 dummy values (, 0.0, 00:00) to the end of all the short lines in my dayfile.txt (fortunately my history only goes back to late October).
It works ok, but I don't know if it's good for the longer term.
Cheers
Re: Display data from SQL in a table on your website
Posted: Mon 08 Feb 2010 1:20 am
by TNETWeather
If you remove the <br/>'s what do you get. I suspect you will see what you want. Unless you use a with no spaces, the col headers are going to break due to the width of the columns anyway.
Re: Display data from SQL in a table on your website
Posted: Mon 08 Feb 2010 4:59 am
by GraemeT
Hi Kevin,
First up, this is daj's code, not mine, I'm just making use of it.
Removing the <br/>'s stops the text wrapping around to the next line within the cell.
Using or a space doesn't cause a break, the text just disappears from view off to the right.
<br /> seems to be the only way to break the lines, but w3c validation fails at each occurrence in this case.
I suspect it's something in the way jquery operates, but I'll be the first to admit I have a LOT to learn
about php, javascript and mysql, (until 3 days ago I'd
never used MySQL)
so if I've missed something here, let me know....
The pages below show what I mean.
The first page is the original history.php using <br/> and the second has spaces.
As you'll see, the second page doesn't have quite the same appearance.
http://weather.gktnet.com/history/historic.php
http://weather.gktnet.com/history/historic_.php
Re: Display data from SQL in a table on your website
Posted: Mon 08 Feb 2010 5:20 am
by TNETWeather
Was just a thought. With normal cols in a table it would work, but I just tried doing it with your page and got the results you mentioned.
He is using JavaScript in the header section to deal with sorting etc... I suspect that it could be adjusted via CSS, but not really sure. He would be better and knowing what is going on.
Re: Display data from SQL in a table on your website
Posted: Mon 08 Feb 2010 9:40 pm
by daj
Hi Graeme
GraemeT wrote:
The first, regarding the 'colnames' definition. Is there any alternative to using <br/> to insert a line-feed in those headings which require two lines?
The xhtml spec says that <br/> isn't allowed. Not that it matters much to most browsers, though.
There are a number of possible solutions -- I have had limited success with CSS. A quick 'cheat' to pass the XHTML spec is to move the Javascript to it's own file. So copy all the text between the last <script> and </script> but not the two tags, save it, then call it from within the document...<script src="build-table.js" type="text/javascript"></script>
To fully comply you need to 'fix' the blank table that is defined further down. I currently have a table with nothing in it and the Jquery fills it later. However XHML will not pass this so you would need to change it to include a row and a data cell...<table id="list"><tr><td></td> </tr></table>
It will now pass

as mine does!
My second comment relates to dayfile.txt.
Lines in dayfile.txt since the Cumulus release which added 'Highest Average Wind Speed' and 'Time of Highest Average Wind Speed' are longer by 2 values.
This caused MySQL v5.1.43 to only use the most recent (longer) lines and then report errors for all the rest, having been told to expect 18 values, but only getting 16).
I added 2 dummy values (, 0.0, 00:00) to the end of all the short lines in my dayfile.txt (fortunately my history only goes back to late October).
It works ok, but I don't know if it's good for the longer term.
That is strange, as my dayfile.txt, like so many, will start off with the two fields missing at the end and then they appear after they were added to Cumulus. However they import no problem and are assigned no values. The script does not actually care how may fields it imports (I did that on purpose), but it then creates 18 and if there is no value in a field in the array it will be blank
Can you send me your dayfile just to try on my version (5.1.30)