Forum Moderators: open

Message Too Old, No Replies

Retrieving pretty information

         

Mr_Cat

2:31 pm on Nov 14, 2008 (gmt 0)

10+ Year Member



Hi folks,

I'm new to databases and php. I'm corking with mysql/php on my server, and I have a copy of wordpress installed as well as some forum software.

It's the former software I'm concerned with just now, but it applies to all. I want to get information from my mysql database and present it in a nice fashion on pages of my site. First I tried a simple rss feed to my site to displey recent articles published, but there is no formatting, just a big block of text. Next I started to look into accessing the database more directly from the site with some php (all done for me by dreamweaver). It's a good start and something to learn from, but still just retrieves the text of a published article in one big block, no formatting.

I have since been scouring the web to find out how to present my data nicely in a pleasing to the eye format, but all I can seem to find is the basics of linking to a database and retrieving the info as I already have.

I usderstand that rss feeds aren't meant to look hugely pretty, and I have a lot more flexibility just grabbing stuff from the database, but without knowing much atall about mysql and php, and being on a tight schedule I'm feeling a little stuck! Does anybody know of a good place to start?

I've looked into feedburner and similar things, but I gather they're not quite 100% what I'm after

What I'm really trying to do is get a system where users can publish their own content to the site in as easy and automated a fashion as possible. This can't be too ambitious surely, the above seemed the best method to me.

Hope I'm in the right place, I wasn't quite sure where to post this request!
Cheers
Mr Cat

rocknbil

3:11 pm on Nov 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know if this will help . . . . but IMO "raw text" is the best type of data to work with.

If your text has line breaks:

paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph

paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph

you could extract it and using your program, sub out the beginning and ending line breaks with paragraph tags, store it in a variable.

You then open a template which has a "marker" that you sub out for content. The template is a plain old HTML file you style like any other HTML file.

Rough example, perl-ish approach used (s =~ is equivalent of eregi() or other php substitution methods:)

select title, content from db where id='12345';
($title,$content)=(row result method);

Add the first and last paragraph tags:

$content = '<p>' . $content . '</p>';

Sub out the newlines/carriage returns for 'graphs between:

$content =~ s/^(\s+)$/\<\/p\>$1\<p\>/g;

Basically, the above says, if you find a blank line, put a </p> before it, a <p> after it, and maintain the newline so you will still have a blank line between paragraphs.

open template, read it in line by line:

while ($line = <TEMPLATE>) {
if ($line =~ /HEADING\_MARKER/) {

$line =~ s/HEADING\_MARKER/$title/g;

}
if ($line =~ /CONTENT\_MARKER/) {

$line =~ s/CONTENT\_MARKER/$content/;

}
$final_output .= $line;
} (end while loop)
(close template)

You now have the "whole page" inserted into the template with clean 'graphs that are styled via the CSS in the template, stored in "$final_output."

print "$final_output" out to browser, your plain text is now styled to fit your site.

It can be much more complex with substitutions for last modified date or other database fields, searching for other elements in the "$content" to substitute, but that's the gist of an approach that can be ported to any page template.

[edited by: eelixduppy at 5:14 pm (utc) on Nov. 14, 2008]
[edit reason] disabled smileys [/edit]