TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 320
  • Total: 320

PHP Article: Use SMF Forum posts

Started by DJ Doena, January 20, 2009, 09:55:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DJ Doena

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. :)

JPDeni


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);

DJ Doena

Thx, it worked.

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

http://www.dvdcollectorsonline.com/index.php

ZarPrime

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

DJ Doena

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?

ZarPrime

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

JPDeni

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']
}


This website is proudly hosted on Crocweb Cloud Website Hosting.