TinyPortal

Development => Support => Topic started by: DJ Doena on January 20, 2009, 09:55:11 PM

Title: PHP Article: Use SMF Forum posts
Post by: DJ Doena on January 20, 2009, 09:55:11 PM
Hi,

it's not a problem for me to access the database and find the body of a forum message.

But How do I get PHP to parse the message for BB-Codes and "translate" them into HTML just as the forum does it?

Thx. :)
Title: Re: PHP Article: Use SMF Forum posts
Post by: JPDeni on January 20, 2009, 10:17:42 PM

require_once("Subs.php");

// pull the post from the database. Assuming the variable $post has the body of the post in it

echo parse_bbc($post);
Title: Re: PHP Article: Use SMF Forum posts
Post by: DJ Doena on January 20, 2009, 11:40:33 PM
Thx, it worked.

Now I have a random movie review on my start page :-)

http://www.dvdcollectorsonline.com/index.php
Title: Re: PHP Article: Use SMF Forum posts
Post by: ZarPrime on January 21, 2009, 12:05:39 AM
DJ,

This seems to work very well on your site.  Any chance you could post the entire code snippet for that article and we can find some place to put it so others can take advantage of what you have done if they want to?

Thanks,
ZarPrime
Title: Re: PHP Article: Use SMF Forum posts
Post by: DJ Doena on January 22, 2009, 06:35:27 AM
Hi,

it's rather specific code that depends a lot on our forum structure. But if there's still interest I have no problem.

But I have another problem. I open a MySQL connection, do my stuff and close it again. But if I do that, IE(7) doesn't show any page but a browser-generic error message that he can't display the page.

If I remove the close command, it works. I even tried to rename the variable in case it collides with some other, but it didn't help.

How the hell does IE even know that I close on a server-side PHP script a database connection?
Title: Re: PHP Article: Use SMF Forum posts
Post by: ZarPrime on January 22, 2009, 12:56:09 PM
I certainly don't know the answer to that one.  JPDeni might be able to come to your aid on that one as she's much more attuned to the workings of the database and such.

I only thought that what you were doing with this might be of interest to others, that's why I mentioned it.

ZarPrime
Title: Re: PHP Article: Use SMF Forum posts
Post by: JPDeni on January 22, 2009, 03:24:45 PM
QuoteI open a MySQL connection, do my stuff and close it again

Don't do that. The MySQL connection is already open before the article is rendered and will close on its own after the whole page is finished.

QuoteHow the hell does IE even know that I close on a server-side PHP script a database connection?

It's not IE. It's the database.

The best way to access the database is through the SMF itself:


global $db_prefix;

$query = db_query("SELECT blah blah bla
FROM {$db_prefix}table name
WHERE blah blah
                        AND blah blah
                        ORDER BY blah
                        LIMIT whatever", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query)) {
   // process the data using the variables $row['field name']
}