Building HTML tables from data in database

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
MB34
Forum Newbie
Posts: 6
Joined: Wed Jun 16, 2010 9:38 pm

Building HTML tables from data in database

Post by MB34 »

I'm trying to recreate a "ballot" in an HTML table. The PDF version of the ballot (from the 2008 election) is located here:
http://174.120.31.194/~eshipman/RYB/Precinct0015.pdf

Note: The PDF has NOTHING to do with this. I am not parsing the PDF or using it at all, it is only being used to show what the actual ballot looks like.

I need it to look like this: http://174.120.31.194/~eshipman/RYB/sub.htm
(a, syntactically modified by me, mockup from the customer, I am programming the back end.)

The data in the PDF is already in a database and I am trying to create an HTML table to mimic the one on the sub.htm page based on the data
from the database tables.

I am returning the data from a database in separate arrays, i.e.
PRESIDENT
CONGRESSIONAL
COUNTY
NONPARTISON
AMENDMENTS

The crux of the problem is when to break columns in the table. I am struggling mightily with this. It really depends on the number of
elections and candidates for the first table. However, the amendments table is going to be difficult because you can't just count the number
of rows based on entries in the database table.

Figuring how to break the columns has really got me stumped. I thought I'd be able to calculate the "lines" and build a table where the columns
break where I want but when I began looking at how the amendments text flowed, it proved too difficult to use that method.

This will be used in several different localities so it has to be dynamic. Each election will have different number of "entries" so I have no way
of knowing, beforehand, how "tall" the table needs to be. I can use templates for each race but, again, I don't know how many there will be.
And then, again, there are the amendments, the text for each of those is variable so determining the layout for those is doubly-difficult.

The visitors will not be actually making selections on the ballot, this is for presentation purposes only. Believe me, I have tweaked this much
more than it was when I originally got it from the customer. You should have seen how crappy the markup was. I feel it is kind of stupid
to mimic the look of the PDF ballot, as well, in fact, I asked them why they just didn't present the PDF ballot(s) and got no answer.

I don't think I've ever seen an "algorithm" to work this kind of thing with HTML tables.

Any ideas?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Building HTML tables from data in database

Post by andyhoneycutt »

Ok, I may totally be missing something here, but why don't you just use a 3-column table and put floated divs in it? They should stack up on each other nicely enough.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Building HTML tables from data in database

Post by josh »

You have to figure out what you want to measure. Are you going to measure # of candidates? Better would be to measure amount of text. Maybe # of words or even better # of characters.

From there you can decide on a reasonable threshold. Normally I'll put a tracer message in the app "there are this many characters in this column: 450", so the client can edit the text and play around with it. I'll let them decide what the optimal threshold should be.
Post Reply