Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Table Built from PHP

Credits go to mEmO, BAF, bamccaig, CGamesPlay, Crazy Photon, Inphernic, le_y_mistar, Mark Oates, Tobias Dammers, and X-G for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
Table Built from PHP
Onewing
Member #6,152
August 2005
avatar

html, php and a little javascript. There, now you know the extent of my web building knowledge. :)

Don't want to read my ramblings? Then go to the bottom of the post!

Anyway, I'm working on making my website (seems I almost never have time to). I've got all my games listed, ranging from ideas to completed to dead on my harddrive. Each game has a small, one paragraph description and a screenshot, plus a few button-slash-links for a spot on forums, a download, etc. Know, you put all of these sections on one page and you have a lot of scrolling to do. So, my idea was to put a table (literally) of contents at the top, with a hop link to the given game.

The table is built from php code that looks up a database storing information about the games. The table includes several things like what version, if it has a download, what I used to make it and so on. You can click the column title at the top of the table to rebuild the table sorted on that column.

I realized this was bloated so I'm creating a condensed version which only has the most important information. I also want to work on coloring the rows. Like, every other row when it is sorted by title and maybe color it by blocks when sorted by anything else.

Ultimately, this might be really slow, since when you click on a column header to rearrange the table, the entire page has to be regenerated (including the lengthy set of sections below). I suppose I could use a frame (or maybe an iframe?), but I'm not sure if that is a good route to take.

My question is, is building a table using PHP a good idea? Moreover, is it an acceptable coding practice or am I just abusing the concept of PHP here. Remember what I said at the beginning and my lack of web-building knowledge; I come up with ideas that I think are good but might have problems that my limited knowledge doesn't foresee. :)

------------
Solo-Games.org | My Tech Blog: The Digital Helm

X-G
Member #856
December 2000
avatar

It's a good idea, it's appropriate use of PHP, and it's recommended.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

mEmO
Member #1,124
March 2001
avatar

I don't see how it is different than generating the rest of the page with PHP. In short, yes, it's a good idea.

[edit]

Blasted, I need to stop reading other forums while posting.

---------------------------------------------
There is only one God, and Connor is his son!
http://www.memocomputers.com
Happy birthday!

Onewing
Member #6,152
August 2005
avatar

Thanks!

Quote:

I don't see how it is different than generating the rest of the page with PHP.

This might be my biggest concern. The page itself is rather lengthy, and since the table is going to be sorted by whatever column header they click and the whole page is rebuilt, instead of just the table. I might be able to use iframe though, which was an idea I had writing the above post. I'll have to experiment with it.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Inphernic
Member #1,111
March 2001

Quote:

Ultimately, this might be really slow, since when you click on a column header to rearrange the table, the entire page has to be regenerated (including the lengthy set of sections below). I suppose I could use a frame (or maybe an iframe?), but I'm not sure if that is a good route to take.

Or you could use JavaScript to provide real-time sorting, falling back to regeneration where applicable.

BAF
Member #2,981
December 2002
avatar

Unless you have tons (and I mean tons) of data, it should't cause that much of a performance hit to reorder and regenerate the whole page.

Crazy Photon
Member #2,588
July 2002
avatar

And don't forget to not use tables for the layout, just for data. This website illustrates what I mean, and also has a lot of useful guidelines to build the web page.

-----
Resistance is NEVER futile...

bamccaig
Member #7,536
July 2006
avatar

I wonder how JavaScript would perform sorting the data itself. It would be nice, but I bet you'd be left writing your own sorting functions (or finding some prewritten ones on the Web).

Instead of using an iframe you could put the heading-table on it's own page, like a table of contents, and link to a genaric script, passing the record's primary key in the querystring, that displays a single item's information at a time or; if the average item has relatively little information, link to an anchor target on a paged list of content. Using the count of records in the database, determine which page each item would appear on (using the number of items displayed on a page and the total count) and embed a variable in the querystring like page=x in the linked address so when you load the generic script (php), it would load the xth page of data. For example:

SELECT * FROM MyTable LIMIT 0, 20;

I'm not entirely sure on the SQL or the DBMS you are using so you'll have to look put the syntax appropriate to your tools. I believe that says return all columns from MyTable beginning at record 0 (the first one) and only return 20 rows. The next page might (guessing) look like this:

SELECT * FROM MyTable LIMIT 20, 20;

Then, the address for the item whose primary key was 23 and was displayed on page 2 might look like this (assuming localhost was instead your domain name/IP address):

http://localhost.com/item.php?id=23&page=2

These are my ideas. It might complicate things paging via unique sorting mechanisms because you would likely want the item.php page sorted the same way as your table of contents, which would alter the page a particular item was displayed on and the order the items were displayed on that page. Since the table of contents is separated from the main data it wouldn't be a problem regenerating the data, and therefore, recalculating this information whenever the sorting techique is changed. Then pass that as well via the querystring, for example:

http://localhost.com/item.php?id=23&page=2&sort=2
OR
http://localhost.com/item.php?id=23&page=2&sort=name

I would generally stay away from frames because they don't flow nicely with Web browsers, being that each frame can refresh separately, etc. It's inconsistent and a frustrating experience for the user trying to navigate, IMHO.

I wouldn't shy away from using tables to layout your Web pages though. Browser wars are bad enough on PCs, let alone trying to make your site compatible with portable devices, etc. If your page is professional and has the intent of marketing your skills or is used for commercial purposes, target your sites compatability for the most exposure possible. Otherwise, target your intended audience or provide general browser support (IE/Firefox). Web development tools are poorly designed and inconsistently supported.

Personally, I hate today's Web languages and as a single example want to replace everything SGML based with something more programmer-friendly. I'm no fan of <anything that="looks" like="this" />. I am devising a replacement for Web development that I can only describe as an extensible, byte-coded, C-like language with explicitly defined static-typing, manual memory management (and out of scope backup garbage collection), and graphical concepts derived from full fledged 2D/3D graphic libraries, as well as Flash... It would be rendered in a single official 'browser' , or by a virtual machine or run-time. It would need a standard framework for defining common Web/GUI controls, graphical elements, and animation concepts; as well as for data management and access. From there you could extend it as required, and possibly implement binary libary concepts, etc. There would hopefully be an official IDE designed for it's development with graphical support and debugging, as well as optimizers, and automatically tracked application versioning for update management and ultimately, when you 'installed' an application the client's browser, virtual machine, or run-time would compile it natively for better performance...

Don't hold your breath. ;)

(Sorry for expressing that off-topic idea)

(I don't have time to revise this so hopefully it's not too confusingly written)

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

Personally, I hate today's Web languages and as a single example want to replace everything SGML based with something more programmer-friendly. I'm no fan of <anything that="looks" like="this" />. I am devising a replacement for Web development that I can only describe as an extensible, byte-coded, C-like language with explicitly defined static-typing, manual memory management (and out of scope backup garbage collection), and graphical concepts derived from full fledged 2D/3D graphic libraries, as well as Flash... It would be rendered in a single official 'browser' , or by a virtual machine or run-time. It would need a standard framework for defining common Web/GUI controls, graphical elements, and animation concepts; as well as for data management and access. From there you could extend it as required, and possibly implement binary libary concepts, etc. There would hopefully be an official IDE designed for it's development with graphical support and debugging, as well as optimizers, and automatically tracked application versioning for update management and ultimately, when you 'installed' an application the client's browser, virtual machine, or run-time would compile it natively for better performance...

You mean, the worst of all common programming languages and web technologies, combined into one massive package? Good idea.

Quote:

I wonder how JavaScript would perform sorting the data itself. It would be nice, but I bet you'd be left writing your own sorting functions (or finding some prewritten ones on the Web).

Took me 10 seconds to google this.
Javascript performance, of course, hugely depends on the client machine; since Array.sort() is a core language feature, I'd expect most implementations to use fairly efficient code. Unless the resulting list is very long, say >1000 rows, I guess sorting on the client is worth a shot. OTOH, sorting on the client requires downloading the entire list before displaying it for the first time, which may be an obstacle for large SQL results.
In other words: If your list is short, sort on the client (Javascript), if it's not, or the client doesn't have Javascript enabled, sort on the server. And of course profile.

Quote:

I wouldn't shy away from using tables to layout your Web pages though. Browser wars are bad enough on PCs, let alone trying to make your site compatible with portable devices, etc. If your page is professional and has the intent of marketing your skills or is used for commercial purposes, target your sites compatability for the most exposure possible. Otherwise, target your intended audience or provide general browser support (IE/Firefox). Web development tools are poorly designed and inconsistently supported.

IE != general browser support.
For browsers that support CSS, you have powerful tools to format your site in a reliable way, without resorting to tables. Browsers that don't support CSS are unlikely to provide any useful formatting at all, so those should just display the raw document structure. If something is in a table that isn't supposed to be, especially aural and tactile devices can produce confusing output.
Read the official specs for all the tools & technologies you use (PHP, HTML, Javascript, CSS), and adhere to them. Avoid features that are broken or missing in popular browsers. Test on as many browsers as you can. Design your page so that it still works with the smallest possible subset of HTML; you may want to test it on Lynx, Links, ELinks, or your mobile phone.
If it's a commercial site, and your audience consists mainly of digitally challenged people, then you might want to work around the flaws IE has, just so they don't complain - but when you do, please don't violate the existing web standards.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Mark Oates
Member #1,146
March 2001
avatar

php good.

dynamically generated webpages good.

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

Personally, I hate today's Web languages and as a single example want to replace everything SGML based with something more programmer-friendly. I'm no fan of <anything that="looks" like="this" />. I am devising a replacement for Web development that I can only describe as an extensible, byte-coded, C-like language with explicitly defined static-typing, manual memory management (and out of scope backup garbage collection), and graphical concepts derived from full fledged 2D/3D graphic libraries, as well as Flash... It would be rendered in a single official 'browser' , or by a virtual machine or run-time. It would need a standard framework for defining common Web/GUI controls, graphical elements, and animation concepts; as well as for data management and access. From there you could extend it as required, and possibly implement binary libary concepts, etc. There would hopefully be an official IDE designed for it's development with graphical support and debugging, as well as optimizers, and automatically tracked application versioning for update management and ultimately, when you 'installed' an application the client's browser, virtual machine, or run-time would compile it natively for better performance...

Haha! ;D Buddy, it's Active X!

[edit]
Ooh, I like the RO‌FL -> ;D transliteration :)

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

Tobias Dammers said:

You mean, the worst of all common programming languages and web technologies, combined into one massive package? Good idea.

What did I mention that you consider bad to have in a development package? I don't claim to know enough to develop it. I just dream of something powerful and done right. The definition is constantly evolving.

Tobias Dammers said:

Javascript performance, of course, hugely depends on the client machine; since Array.sort() is a core language feature, I'd expect most implementations to use fairly efficient code.

I guess I wasn't trying very hard. Developing in JavaScript on a regular basis I've learned not to get my hopes up.

Besides, Array.sort() appears to sort a single Array (which is like a single column). I don't have time to look very hard (I'm at work), but http://w3schools.com doesn't seem to say anything about sorting an entire table of data. In other words, storing a table worth of information in JavaScript (however you go about it) and trying to sort it all based on a single column doesn't seem easy. Again, I'm not able to spend much time looking though.

http://w3schools.com also say that sorting is done alphabetically by default so you have to create a function to sort by numbers (let alone dates, etc.). Again, I don't have time right now to figure it out (and it's JavaScript so I'm not all that excited about it anyway).

Tobias Dammers said:

IE != general browser support.

I didn't mean that IE followed the standards. I meant that IE is one of the most popular browsers.

Currently, on Allegro.cc 42% of users are running Firefox and 40% of users are running IE. The next runner up is Opera with 6%. These figures are according to A.cc. I don't know how that detection is implemented and can't guarantee it's accuracy. Still, I would expect similar results in the average user base. And the farther away from technical people and the closer your audience gets to Windows the use of IE should increase.

I usually use IE in Windows and Firefox in Linux. I like them both and hate Web browsers in general.

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

What did I mention that you consider bad to have in a development package?

Let me elaborate:
extensible - that's a good thing.
byte-coded - as in "not human readable"? Remember, obfuscation is not encryption. Current web languages (PHP, HTML, JS) are already fairly efficient to parse.
C-like language - Nooooooo! C is great for kernel and driver programming, but it is not The Tool For The Job for web applications. You being used to it doesn't mean it's the best language for everything.
explicitly defined static-typing - You don't really need that for web stuff. 90% of your data is strings, and everything will eventually be displayed as a string; dynamic typing is nothing more than convenient. The only reason C and C++ have it is that it allows for some performance optimization at compile-time. This doesn't make any sense for an interpreted language, though.
manual memory management - You really want to inherit the number 1 source of errors, exploits, and crashes from C?
and out of scope backup garbage collection - Automatic GC has issues of its own, but most web languages have quite fine implementations already. Using auto-GC together with manual memory management is bound to make things slower and buggier.
graphical concepts derived from full fledged 2D/3D graphic libraries, as well as Flash... - We already have that, and it's being over-used all the time.
It would be rendered in a single official 'browser' - Who is going to write this whole new browser for all the platforms (not just windows and linux and macos, but also palmtops, cellphones, aural and tactile devices, some of the more obscure OSes...) out there? You?
or by a virtual machine - One of the things that bug me with Java. Yet another thing that sits there and eats system resources.
It would need a standard framework for defining common Web/GUI controls, - What, HTML <FORM> not good enough for you?
graphical elements - <IMG>?
animation concepts; - <OBJECT>? Flash? Animated GIF if you have to?
for data management and access. - SQL? PHP filesystem functions?
From there you could extend it as required, and possibly implement binary libary concepts, etc. - PHP can call pretty much everything the shell can...
There would hopefully be an official IDE - Just one? And that would be a 10 GB download, and require a Core 7 CPU and 15 TB of RAM?
graphical support and debugging, - Firefox has all that built-in, duh
automatically tracked application versioning for update management - CVS?
and ultimately, when you 'installed' an application I take great offense at web sites trying to "install" anything on my machine. Did you know that a script runs on the browser without installing anything at all? ::)
would compile it natively for better performance... - That's called JIT compiling, and Java already does that. Also, scripting languages generally come with a lot of features built-in, and those are very likely to be optimized for the given platform (e.g. PHP's array sorting functions). BTW, the main performance bottleneck for most web sites is still the network bandwidth.

All those things create this image in my mind of a huge, bloated, slow, unresponsive, useless blob occupying half my HDD just so I can view your site. No thank you.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

le_y_mistar
Member #8,251
January 2007
avatar

tables are good. php is a good RAD tool

It comes down to if you can write good code to generate clean tables.

-----------------
I'm hell of an awesome guy :)

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

I usually use IE in Windows and Firefox in Linux. I like them both and hate Web browsers in general.

What's to like about IE? OK, it starts up a little faster than FF or Opera, but that's about it.

Quote:

Besides, Array.sort() appears to sort a single Array (which is like a single column). I don't have time to look very hard (I'm at work), but http://w3schools.com doesn't seem to say anything about sorting an entire table of data. In other words, storing a table worth of information in JavaScript (however you go about it) and trying to sort it all based on a single column doesn't seem easy. Again, I'm not able to spend much time looking though.

http://w3schools.com also say that sorting is done alphabetically by default so you have to create a function to sort by numbers (let alone dates, etc.). Again, I don't have time right now to figure it out (and it's JavaScript so I'm not all that excited about it anyway).

Well, Javascript is "the" web scripting language, and if you don't like it, there's little you can do. You can't really feasibly write web pages in anything but HTML / XHTML, and you can't feasibly provide client-side scripts in anything but Javascript (unless you like to support ActiveX, in which case this conversation is over).
Anyway; I'd use an array of arrays, and provide a custom compare function to pass to sort(). There could be a global telling the custom comparer by which column to sort.
But in fact, I'd really just sort server-side and see if that works feasibly (for my own site, it does).

Quote:

tables are good. php is a good RAD tool

Yes. No matter what Billy Boy is trying to teach us.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Inphernic
Member #1,111
March 2001

Table sorting works well/fast enough to be considered for small datasets (20-50 records or so should be reasonable when considering 'any' client machine). For big datasets, page regeneration is a better option. Considering you are listing games, I'd say you're going with the small dataset scenario.. unless you plan on making 50+ versions of Toggles.

Quote:

php is a good RAD tool

what

Tobias Dammers
Member #2,604
August 2002
avatar

Since you have to code the page regeneration scenario anyway to support clients without javascript, I'd say try that first and see if the result is acceptable (in terms of execution speed and server load).

Quote:

what

Either this or that.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Inphernic
Member #1,111
March 2001

Quote:

Either this [en.wikipedia.org] or that [rad.org.uk].

I'd say the latter, considering PHP itself isn't a RAD tool.

Tobias Dammers
Member #2,604
August 2002
avatar

Not explicitly, no.
It does allow for rather rapid application development though... ::)
And it's not really a dance development tool either...

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Onewing
Member #6,152
August 2005
avatar

Quote:

Considering you are listing games, I'd say you're going with the small dataset scenario.. unless you plan on making 50+ versions of Toggles.

Good glory, don't let me get away with doing something like that. Although, I am revamping it to 2.0 with some major changes to the game mechanics (as an attempt to see if I've increased the "fun factor" of the game, something that's more difficult than optimizing and/or producing efficient algorithms).

Anyway, I'm using the table-built-by-php method for several different things on the site. One, the listing of games I've worked on (which is about 20, only about 3 of which have made it through the beta stages). Two, a more detailed leader board of the top 100 highscores from Toggles (an early version of that is here and was only about ten minutes of work, obviously you can see I stole a template from OSWD). Third, a site for Invictis that I mentioned a while back and for the "cards" of the game, which is going to be a very large number, plus it will have the images for the card (FuriousOrange has made some very impressive work for this and I've been promising him a site showcasing it for forever).

Thanks to all for your knowledge. Hopefully I will use it wisely. ;)

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Ron Ofir
Member #2,357
May 2002
avatar

Quote:

obviously you can see I stole a template from OSWD

You can't steal templates from OSWD, that's what it's for! Though you could have spent one more minute to erase all irrelevant stuff.

Onewing
Member #6,152
August 2005
avatar

Quote:

You can't steal templates from OSWD, that's what it's for!

:-X;D

Quote:

Though you could have spent one more minute to erase all irrelevant stuff.

Actually, it would have only taken a second. But I only had five minutes, not five minutes and one second! :-/

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Inphernic
Member #1,111
March 2001

Quote:

It does allow for rather rapid application development though...

Nah, not really. Sure, one simple site and/or garbage is fast and easy to write, but it's not that 'rapid' when you are doing something big/serious. There's something interesting on the way though when it comes to PHP..!

Quote:

You can't steal templates from OSWD, that's what it's for!

There is a difference between 1) taking a template + attributing the actual author properly and 2) taking a template + not attributing the actual author but throwing a "CIOYRUGHT BY RON OFFIR BEST WEBS DESINGERS EVAR!?? BTW NEOPETS ROCXXXX" on it instead.

Ron Ofir
Member #2,357
May 2002
avatar

Yup, but he did attribute the actual author properly. Anyway, Ofir is with one F!!!! AND MYSPACE PWNS NEOPETS!!!! LOLOL OMGFGFGFGFG111:P

Inphernic
Member #1,111
March 2001

Quote:

Yup, but he did attribute the actual author properly.

Yes - after he got caught. :P

 1   2   3 


Go to: