The best way to display some statistical info on a site?
I have a requirement to show three different types stats on the home page of a website. These are controlled/managed by an admin. For example, these are,
type A开发者_运维问答 items - 1200,
type B items - 4500,
blah items - 1800
I can just create a table, homepage_stats (id, first_field, second_field, third_field). Then on homepage SELECT first_field as type_a_item etc etc from homepage_stats and display whereever I want to display it. An admin user can anytime update these values. Is there any better way to do this. I mean without using tables or anyother?? what would you suggest?
Thanks all.
Using a database would be convenient and scalable. A table with name, value and display name columns would probably work best. You could then have the following rows:
name value displayName
--------------------------
typea 1200 Type A
typeb 4500 Type B
blah 1800 Blah
Using a table would also make it trivial to create a page for the admin to use for updating these values and even adding new ones. Having the display name would make it easy to automate the process of selecting and displaying each statistic with the appropriate label on the home page.
It depends on what the data means and where it comes from. Are you counting the number of items of type A, type B, and so on? Are these just three arbitrary figures that come from the admin and need to be displayed on the page?
You could certainly put them in a table. That would be one way to do it.
You could put them in individual text files then the admin only needs to modify a text file to change the value displayed.
Say your data is in /var/www/typea.txt, /var/www/typeb.txt, and /var/www/typec.txt
then you read them in with file_get_contents()
$typea = file_get_contents('/var/www/typea.txt');
$typeb = file_get_contents('/var/www/typeb.txt');
$typec = file_get_contents('/var/www/typec.txt');
and you can echo or print where ever you need them. Again, it depends on what is most appropriate for the admins to update.
As for displaying the data on the page in HTML, that would depend on what the data is and how it is related. Nothing wrong with using tables if it's tabular data that should be displayed in a table. Maybe it needs to be displayed in a textual format? Maybe it gets displayed as an unordered list. There are myriad choices.
Your mileage may vary, --Mark
I think what you have mentioned should be your best bet. Someone just made a comment about using HTML tables which I don't think you are asking. The person making the comment probably just deleted it cause it is long gone.
My suggestion is it sounds like you know what you are doing and to go aheand and proceed with storing this data in a table and then pulling it in your app and loading it.
精彩评论