TinyPortal

Development => Support => Topic started by: knat on July 25, 2007, 03:37:00 PM

Title: got a question about how to use this code - please help
Post by: knat on July 25, 2007, 03:37:00 PM
in my sources/messageindex.php i have this code that allows me to sort the topics in some of my boards by subject.. it works fine.. but now i need it for 10-20 boards and my question is:

Do i copy the code for every board like shown in this example or is there an easy way to add multiple boards to this code ??

example with two boards being sorted by subject

// View all the topics, or just a few?
$maxindex = isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) ? $board_info['num_topics'] : $modSettings['defaultMaxTopics'];
if (!isset($_REQUEST['sort']) && $board == 131)
$_REQUEST['sort'] = 'subject';
if (!isset($_REQUEST['sort']) && $board == 184)
$_REQUEST['sort'] = 'subject';


So do i have to make more of this


if (!isset($_REQUEST['sort']) && $board == XXX)
$_REQUEST['sort'] = 'subject';


where XXX is the board ID, or is there another way..  ::)

I know this is not actualy TP related but i need an answer this week.. and i know this is easy to answer for some of you here on TP

Thanks to anyone who can tell me
Title: Re: got a question about how to use this code - please help
Post by: jacortina on July 25, 2007, 03:51:29 PM
I think this would work:

Change
// View all the topics, or just a few?
$maxindex = isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) ? $board_info['num_topics'] : $modSettings['defaultMaxTopics'];
if (!isset($_REQUEST['sort']) && $board == 131)
$_REQUEST['sort'] = 'subject';
if (!isset($_REQUEST['sort']) && $board == 184)
$_REQUEST['sort'] = 'subject';


To:
// View all the topics, or just a few?
$maxindex = isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) ? $board_info['num_topics'] : $modSettings['defaultMaxTopics'];
$sort_boards = array(131, 184, 9999, 9999, 9999, 9999, 9999, 9999, 9999);
if (!isset($_REQUEST['sort']) && in_array($board, $sort_boards))
$_REQUEST['sort'] = 'subject';


Just have to have the right list of bord numbers going into the array $sort_boards. And instead of indivdually checking values, the in_array() function checks if, well, the first argument is in the array which is the second argument.
Title: Re: got a question about how to use this code - please help
Post by: knat on July 25, 2007, 03:55:01 PM
Thanks alot.. i will try it and let you know the result  :) Thanks alot  :D
Title: Re: got a question about how to use this code - please help
Post by: knat on July 25, 2007, 03:58:31 PM
Just did it and it works like a charm.. just what i needed..  :D

Thanks for the quick support and sorry for posting non TP related issues  ::)