Page 2 of 2
Re: Database v text files
Posted: Thu 23 Apr 2020 6:20 am
by Sadgit
well not that easy.. I went purely for php so my code has every line with
Code: Select all
echo " </tr>\n";
echo " <tr class=\"td_temperature_data\">\n";
echo " <td>Temperature</td>\n";
echo " <td>$temp $tempunit></td>\n";
echo " <td>Dew Point </td>\n";
echo " <td>$dew $tempunit></td>\n";
echo " </tr>\n";
not the most efficient I suspect. I take it the best way is to ensure I just use php language wehn actually needed and stick to html where possible?
Re: Database v text files
Posted: Thu 23 Apr 2020 6:15 pm
by sfws
Sadgit wrote: ↑Thu 23 Apr 2020 6:20 am
not the most efficient I suspect. I take it the best way is to ensure I just use php language wehn actually needed and stick to html where possible?
It is not as simple as that. Yes there are 2 approaches (all php or stick to HTML to extent possible). But which is better depends on what your aim is:
Writing in HTML as much as you can and only within each table cell using a piece of PHP just to output the value is simplest because you get a web page that is easy to read (just do view source in your browser and you see the whole structure).
sfws wrote: ↑Sun 19 Apr 2020 8:25 am<tr>
<th class="label">Total Rainfall</th>
<td class='site_data'><?php echo "$rfall $rainunit"; ?></td>
<td></td>
<td class='site_data_RH'><?=$rfallY . ' ' . $rainunit;?></td>
<td></td>
</tr>
Writing mostly in php, getting PHP to write out all the structure has the disadvantage that you can't see that if you use "view source" in your browser.
Sadgit wrote: ↑Thu 23 Apr 2020 6:20 am]echo " <tr class=\"td_temperature_data\">\n";
echo " <td>Temperature</td>\n";
echo " <td>$temp $tempunit></td>\n";
echo " <td>Dew Point </td>\n";
echo " <td>$dew $tempunit></td>\n";
echo " </tr>\n";
It is not for me to say which is best for you. Yes, it is marginally more inefficient to enclose in double quotes content that is not variables, so the PHP manual will say your third line above should read to give maximum efficiency for the PHP parser:
Code: Select all
echo "\t" . '<td>' . $temp . ' ' . $tempunit . '</td>' . "\n";
My own opinion (your choice) is that my approach is best for a beginner writing a simple web page, but if you want to vary your web page according to content (i.e. use "If ... else .." conditions or other ways of changing content) then it is simpler to do more in PHP rather than continually swap between PHP and pure HTML. In particular you don't actually need to write separate rows, but can loop through repeating on structure that can be labelled temperature one time and rainfall another. Plus it is easier to do multiple web pages in one skeleton.
I started using PHP years and years ago and I experimented with all the possibilities because I like to feel I have tried everything. My more recent coding has gone back to mostly HTML because it looks so much better, you can see the source easily in your browser, and layout is not a question of adding the right number of "\t" and "\n"! Ok I now do each page separately with less shared, but in some ways that gives me more flexibility.
Re: Database v text files
Posted: Thu 23 Apr 2020 6:33 pm
by Sadgit
Thanks for the detailed replies. I'm trying to stick mainly to html as you say it is easier to read and I did get sick of putting a / instead of a \
I'm trying to keep it simple so far (too much sun to spend it inside on a laptop

) but with the help help here and some search engine fun, I'm getting the hand of it. I won't have anything fancy, but I will be able to display the basics for now... Cheers
Re: Database v text files
Posted: Sun 26 Apr 2020 6:05 pm
by Sadgit
Hi Mapantz, you say your records script is a sql version, I found he tops 10s, I've searched all over the forum but cannot find one. Any pointers please? I know lots of questions from me lately, but enjoying getting data imported in my DB and setting up my new site. Finally moving away from my sluggish old site, setup and host!
Cheers
Mark
Re: Database v text files
Posted: Sun 26 Apr 2020 7:12 pm
by water01
Well done. But that is the hard part and sorting out the errors.
Code: Select all
Warning: Invalid argument supplied for foreach() in /home4/markrennie71/public_html/get-USNO-sunmoon.php on line 361
Warning: Invalid argument supplied for foreach() in /home4/markrennie71/public_html/get-USNO-sunmoon.php on line 372
Also your site initially builds the header and the sidebar with the menu and then takes quite a long time to load the rest of the Home page.
Re: Database v text files
Posted: Sun 26 Apr 2020 7:56 pm
by Sadgit
Ahhh that is the old site on the new host.. Not even looking at that one
Takes years to load hence making my own and starting from scratch.
Re: Database v text files
Posted: Sun 26 Apr 2020 9:59 pm
by water01
So where is the new one so we can all take a look.
