TinyPortal
Development => Block Codes => Topic started by: Arkanna on February 04, 2011, 12:54:42 PM
Hello everyone,
I am the administrator of the web forum for an MMO guild (not WoW though!). Here is my problem.
A while back, our forum was running SMF 1.1.x with TinyPortal beta 4. Back then, I came to this forum for assistance with writing a code block that would look at posts in a certain board, take the individual lines from those posts, and write them on a right-side block. I'm unskilled in the ways of PHP, but this forum was of great help, and I got the code I needed. It worked great.
Recently we upgraded the forum to SMF 2.0 RC4 with TinyPortal 1.0 RC. The code block stopped working, and I was hoping someone could look it over and explain to me the changes I need to make to the code to allow it to function again.
Here is the code:
global $db_prefix;
$board = 2; // change this to the number of the Drop Report board
$number_to_display = 30; // change this to how many you want to display
$query = db_query(
"SELECT mes.body
FROM {$db_prefix}messages as mes
LEFT JOIN {$db_prefix}topics as top
ON ID_FIRST_MSG = ID_MSG
WHERE top.ID_BOARD = $board
ORDER BY top.ID_TOPIC DESC
LIMIT 12", __FILE__, __LINE__);
$total_array = array();
$new_array = array();
while ($row = mysql_fetch_assoc($query))
{
$array = explode("<br />", $row['body']);
rsort($array);
foreach ($array as $item)
$total_array[] = $item;
}
for ($i=0;$i<$number_to_display;++$i)
$new_array[] = $total_array[$i];
echo implode("<br />",$new_array);
Probably a pretty simple problem for a PHP guru! Thanks in advance.
-Ark
I think this should work. The database table row names changed in SMF2. Any that were uppercase were changed to lowercase. Plus the db function names changed, but TP uses it's own so I've changed that as well.
global $db_prefix;
$board = 2; // change this to the number of the Drop Report board
$number_to_display = 30; // change this to how many you want to display
$query = tpdb_query(
"SELECT mes.body
FROM {$db_prefix}messages as mes
LEFT JOIN {$db_prefix}topics as top
ON id_first_msg = id_msg
WHERE top.id_board = $board
ORDER BY top.id_topic DESC
LIMIT 12", __FILE__, __LINE__);
$total_array = array();
$new_array = array();
while ($row = tpdb_fetch_assoc($query))
{
$array = explode("<br />", $row['body']);
rsort($array);
foreach ($array as $item)
$total_array[] = $item;
}
for ($i=0;$i<$number_to_display;++$i)
$new_array[] = $total_array[$i];
echo implode("<br />",$new_array);
IchBin;
Boy, that sure was simple. -_-;; Thanks for your help, it's much appreciated!