News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

trouble converting SMF1 Code to SMF 2 Code

Started by JaGuR, June 29, 2015, 07:16:46 PM

Previous topic - Next topic

JaGuR

Hi guys,

Trying to install a horizontal board menu from my old smf1 forum onto an SMF2 theme but keep getting call to undefined db_query

I have tried changing all fields to the correct fields in the smf2 database, but am still struggling to see what is the problem

function ssi_allBoardsHorizontal($num_top = 100, $output_method = 'echo')
{

global $context, $settings, $db_prefix, $txt, $scripturl,
$user_info, $modSettings;



// Find the top 100 boards
$request = db_query("
SELECT
b.name, b.num_topics, b.num_posts, b.id_board," . 
($user_info['is_guest'] ? ' 1 AS isRead' : '
(IFNULL(lb.id_msg, 0) >= b.id_last_msg) AS isRead') . "
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board 
AND lb.id_member = " .$user_info['id'] . ")
WHERE $user_info[query_see_board]" . 
(!empty($modSettings['recycle_enable']) && 
$modSettings['recycle_board'] > 0 ? "
AND b.id_board != " . (int) $modSettings['recycle_board'] : '') . "
ORDER BY b.board_order
LIMIT $num_top", __FILE__, __LINE__);
$boards = array();
while ($row = mysql_fetch_assoc($request))
$boards[] = array(
'id' => $row['id_board'],
'num_posts' => $row['num_posts'],
'num_topics' => $row['num_topics'],
'name' => $row['name'],
'new' => empty($row['isRead']),
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . 
'.0#board"><b>' . $row['name'] . '</b></a>',
'url' => $scripturl . '?board=' . $row['id_board'] . 
'.0#board',
'name' => $row['name']
);
mysql_free_result($request);

// If we shouldn't output or have nothing to output, just jump out.
if ($output_method != 'echo' || empty($boards))
return $boards;

//echo '<table id="nav">';
echo '<div style="font-size:9px; width:100%"><a name="board"></a>';
echo '<table width="100%">
<tr><td><a href="',$scripturl,'?action=recenttopics#board"><div align="center" style="padding-top:5px; padding-bottom:5px; border: 1px solid ', $_GET['action'] =='recenttopics' ? '#666' : '#CCC','"><b>ALL BOARDS</b></div></a></td>';
foreach ($boards as $board)
echo '<td><a href="',$board['url'],'"><div align="center" style="padding-top:5px; padding-bottom:5px; border: 1px solid ', $board['id'] == $context['current_board'] ? '#666' : '#CCC',';"><b> ', $board['new'] ? '<u>'.str_replace('&amp; Greyhounds','',$board['name']).'</u>' : str_replace('&amp; Greyhounds','',$board['name']),'</b></div></a></td>';
echo '</tr></table>
</div>';
}


Hoping it is just something simple :/

JaGuR

Ok, part of the problem seems to be $smcFunc and the way SMF 2 now queries the database I guess

have added a few changes and am now getting database error :(

// Find the top 100 boards
$request = $smcFunc['db_query']("
SELECT
b.name, b.num_topics, b.num_posts, b.id_board," . 
($user_info['is_guest'] ? ' 1 AS isRead' : '
(IFNULL(lb.id_msg, 0) >= b.id_last_msg) AS isRead') . "
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board 
AND lb.id_member = " .$user_info['id'] . ")
WHERE $user_info[query_see_board]" . 
(!empty($modSettings['recycle_enable']) && 
$modSettings['recycle_board'] > 0 ? "
AND b.id_board != " . (int) $modSettings['recycle_board'] : '') . "
ORDER BY b.board_order
LIMIT $num_top", __FILE__, __LINE__);
$boards = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$boards[] = array(
'id' => $row['id_board'],
'num_posts' => $row['num_posts'],
'num_topics' => $row['num_topics'],
'name' => $row['name'],
'new' => empty($row['isRead']),
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . 
'.0#board"><b>' . $row['name'] . '</b></a>',
'url' => $scripturl . '?board=' . $row['id_board'] . 
'.0#board',
'name' => $row['name']
);
$smcFunc['db_free_result']($request);

// If we shouldn't output or have nothing to output, just jump out.
if ($output_method != 'echo' || empty($boards))
return $boards;

Suki

Make sure  $smcFunc is globalized before calling it:

global  $smcFunc;

your query code
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

live627



Advertisement: