13 replies [Last post]
chewmanfoo
chewmanfoo's picture
Offline
Regular
North Texas, USA
Last seen: 3 years 18 weeks ago
North Texas, USA
Timezone: GMT-6
Joined: 2003-06-15
Posts: 21
Points: 11

I'd like to avoid reinventing the wheel, so if anyone has a good solution for newspaper columns with CSS2, MySQL and PHP, I'd love to hear it. I'm building for my company, so I might be able to pay you for it.

Thanks!

TGecho
Offline
Regular
Last seen: 10 years 49 weeks ago
Joined: 2003-05-06
Posts: 11
Points: 0

Newspaper columns?

I'm not exactly sure what you mean about newspaper columns, but here are some excellent templates. If you don't find what you want there, then come back and I'm sure the people here can help you.

chewmanfoo
chewmanfoo's picture
Offline
Regular
North Texas, USA
Last seen: 3 years 18 weeks ago
North Texas, USA
Timezone: GMT-6
Joined: 2003-06-15
Posts: 21
Points: 11

newspaper columns --- an explanation

Look at a newspaper. See how the fcolumns line up across the page. The text flows down one column, then started at the top of the next and flows down. It has to be dynamic. I'm not sure, but I don't think CSS2 supports this. Does anyone know how to do it in PHP?

dJomp
dJomp's picture
Offline
Enthusiast
York, England
Last seen: 11 years 3 weeks ago
York, England
Joined: 2003-03-23
Posts: 422
Points: 0

Newspaper columns?

I could have sworn I saw a similar effect in the CSS2 spec. Apparently not.

The problem you're going to face working this way is lining the bottom of the columns up. You shouldn't really do fixed-height columns, as user agents render text differently (and users can have different default text sizes) - but then variable-length columns won't get the effect you want.

It'd be pretty easy to knock up a PHP script, count the number of words in the string to print out, divide by the number of columns - if you're feeling daring you could do it by the width of each character and get a really accurate spread of text.

Personally I'd consider whether a newspaper format would work on the internet - I personally wouldn't want to scroll down to the bottom of one column and scroll back up to the next - again, it's difficult to cater for all screen sizes, probably here at work (1280x1024) it'd be OK but some people still run 800x600 (640x480? hope not). But that last bit is just my opinion, I know nothing of the context you're going to use this in.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 12 hours 22 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5054
Points: 2632

Newspaper columns?

Hi Chewmanfoo,
The real problem is that you don't know the length of each column.
If you can break the content into sections such as paragraphs that are approximately the same height or use php to estimate the size of each small block of content you should be able to get the look your after.

:idea: Why not use php to count characters, then each say 200 characters (just a number) find the next period and wrap that section in span tags.
Place them in an array for a moment, then divide the number in the array by the number of columns you want. The rest should be easy just lay them out into the columns.
You should end up with reasonably similar length columns.

Hope that helps.

chewmanfoo
chewmanfoo's picture
Offline
Regular
North Texas, USA
Last seen: 3 years 18 weeks ago
North Texas, USA
Timezone: GMT-6
Joined: 2003-06-15
Posts: 21
Points: 11

All good responses - funny CSS2 doesn't have this

Thanks everyone! I did notice that in the CSS3 spec, there's support for this http://www.w3.org/TR/css3-multicol/ That's nice. Now, I'm taking bets on how long it will take for this option to appear in my favorite browser (mozilla.) Anyone want to wager?

dJomp
dJomp's picture
Offline
Enthusiast
York, England
Last seen: 11 years 3 weeks ago
York, England
Joined: 2003-03-23
Posts: 422
Points: 0

Newspaper columns?

Good, I'm glad to know I didn't imagine reading that... Laughing out loud

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 12 hours 22 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5054
Points: 2632

Newspaper columns?

I'd like to think it would be supported soon, but in reality I know it willl take a long time. Firstly you can count IE out for the next couple of years as no development for future versions will be released without the purchase of an operating system.

Microsoft to abandon standalone IE
I'm not sure how much support they would have for CSS3 anyway.

Then it would take a few years before significant numbers of users upgrade.

Mozilla , Opera and Netscape will keep developing and implementing the standards as best they can.

Heck I'm going to miss my bus.
Don't hold your breath, Im not even sure when CSS3 is due to be released, but I do know when my bus is coming Wink

eirikra
Offline
newbie
Lillehammer, Norway
Last seen: 10 years 39 weeks ago
Lillehammer, Norway
Joined: 2003-07-16
Posts: 1
Points: 0

hmm...

I sorta just came here outta nowhere, but I saw this hread and thought it was so interesting I needed to reply:)
My suggestion is that you use php the count the words in the article (like mentioned earlier). Use the explode() function to split the article into single words and put it in a array. "count()" (pretty self-explaining) counts the values in the array. Then make some kind of if-loop to find out if you're halfway through the article, and then start a new column. Does this make any sense? Anyway... PM me if you need further help.

Hawk
Offline
Regular
Soton, UK
Last seen: 10 years 37 weeks ago
Soton, UK
Joined: 2003-07-29
Posts: 7
Points: 0

Newspaper columns?

Unofficially Netscape supports such

They should really make this part of CSS and implement is ASAP

http://www.utoronto.ca/webdocs/HTMLdocs/NewHTML/multicol.html

There are no great workarrounds TMK Sad

If you really need control over layout, consider using Flash instead of HTML+CSS Shock

... the lack of this multi column support is probably why a lot of sites use PDF for such documents

Daniel
Daniel's picture
Offline
Enthusiast
Last seen: 21 weeks 4 hours ago
Timezone: GMT+10
Joined: 2003-03-12
Posts: 76
Points: 0

Newspaper columns?

Hawk wrote:
Unofficially Netscape supports such

Does it still support it? I just checked out that link you posted in NS7 and it doesn't seem to be working.

Before you ask... yes, I did scroll to the bottom of the page! Smile

d3signmonk3y
d3signmonk3y's picture
Offline
Enthusiast
Toledo, Ohio
Last seen: 10 years 37 weeks ago
Toledo, Ohio
Timezone: GMT-4
Joined: 2003-07-29
Posts: 59
Points: 0

Newspaper columns?

I'm new here but hopefully will be able to contribute some of what I've learned in the future.

The best three column "newspaper" layout I've seen is the International Herald Tribune site, which gives you the option to switch between one and three column layouts at the bottom. It works better in some browsers than in others (I know... goes without saying). I keep meaning to tear through their code and look at what's going on, I've just havn't found the time yet.

http://www.iht.com/articles/104585.html

(When you switch to three column layout you may have to reload the page to see the true layout)
[/url]

paCkeTroUTer
paCkeTroUTer's picture
Offline
Enthusiast
Melbourne, Australia
Last seen: 48 weeks 4 days ago
Melbourne, Australia
Timezone: GMT+10
Joined: 2003-06-27
Posts: 241
Points: 2

Newspaper columns?

That site is so kewl..... Smile I like the navigation when you click on the columns itslef you can go next or previous page.

http//melbourne.ug.php.net

seth1334
Offline
newbie
Last seen: 9 years 17 weeks ago
Joined: 2004-12-14
Posts: 1
Points: 0

Newspaper columns?

I know this is an old thread, but it may be helpful for anyone else that Googles for the same thing I did:

php routine to split my text into 2 columns (sometimes I'm soo lazy and can't be bothered writing one myself).
Thanks to eirikra for the psuedo-code.

This will output an HTML table, 2 columns of 200pix wide:
I didn't want the text split exactly in half, because it doesn't look quite right in my application, but you can play with the "halfthewords" variable, of course.

function newspapercolumns($str) {
$textout = $str;
$thewords = explode(' ', $textout);
$numwords = count($thewords);
$halfthewords = $numwords*3/5;
$wordcounter = 0;
$textout = "<table cellspacing='0' cellpadding='0'><tr><td width='200' valign='top'>\n";
while ($wordcounter < $halfthewords) {
$textout .= $thewords[$wordcounter]." ";
$wordcounter++;
}
$textout .= "\n</td><td width='20'>&nbsp;</td><td width='200' valign='top'>\n";
while ($wordcounter <= $numwords) {
$textout .= $thewords[$wordcounter]." ";
$wordcounter++;
}
$textout .= "\n</td></tr></table>";
return $textout;
}