Coding Examples
This part of the website shall help you by giving you example codes to try out and to use within your own project. There is a great variety of examples. From one-liners to small/great projects.If you have a code example yourself, feel free to contact me, so I can put it into this very example site.Code examples are grouped by topics (such as posts or users).
Examples: Threads
Following code examples are associated to threads of your board.
closeThread
- No example yet
createThread
Example 1:
$data = array(
'fid' => 11,
'subject' => 'New Thread',
'uid' => $MyBBI->mybb->user['uid'],
'username' => $MyBBI->mybb->user['username'],
'ipaddress' => get_ip(),
'message' => 'This is a supercool message'
);
$create = $MyBBI->createThread($data);
print_r($create);
getBusyThreadsWithinTimespan
Example 1:
/**
* This example is taken from my testing board
* Parameter of function is "86400" (= 24 hours) by default
*/
$busy_threads = $MyBBI->getBusyThreadsWithinTimespan();
echo '<pre>'; print_r($busy_threads); echo '</pre>';
// Now here is an example output, where you can see the structure of the returned array
/*
Array
(
[0] => Array
(
[tid] => 2
[fid] => 5
[subject] => Testing
[uid] => 1
[username] => admin
[lastpost] => 1243545630
[lastposter] => admin
[lastposteruid] => 1
[views] => 4
[replies] => 3
[postamount] => 2
[posts] => Array
(
[0] => Array
(
[pid] => 5
[message] => omg lets make this one busy?!
[uid] => 1
[username] => admin
[dateline] => 1243545630
)
[1] => Array
(
[pid] => 4
[message] => hey hey hey
[uid] => 1
[username] => admin
[dateline] => 1243545623
)
)
)
[1] => Array
(
[tid] => 1
[fid] => 11
[subject] => New Dynamic Thread
[uid] => 1
[username] => admin
[lastpost] => 1243545836
[lastposter] => admin
[lastposteruid] => 1
[views] => 3
[replies] => 1
[postamount] => 1
[posts] => Array
(
[0] => Array
(
[pid] => 6
[message] => Now what is this - BUSY
[uid] => 1
[username] => admin
[dateline] => 1243545836
)
)
)
)
*/
getLatestActiveThreads
Example 1:
// Following code fetches the latest active threads and shows the thread titles
$latest_active_threads = $MyBBI->getLatestActiveThreads(2, 5, true);
foreach ($latest_active_threads as $latest_active_thread)
{
echo $latest_active_thread['subject'].'<br />';
}
getLatestThreads
Example 1:
// Following code fetches latest threads from the forums 4, 6 and 12
$forums = array('4', '6', '12');
$fields = 't.`tid`, t.`fid`, t.`subject`, t.`uid`, t.`username`, t.`dateline`, t.`views`, t.`replies`, t.`numratings`, t.`totalratings`'
$latest_threads = $MyBBI->getLatestThreads($forums, $fields, 5, true, true, false);
foreach ($latest_threads as $latest_thread)
{
echo $latest_thread['subject'].'<br />';
}
getThread
Example 1:
$thread = $MyBBI->getThread(1);
print_r($thread); // Output of thread data
getUnreadThreadsOfForum
- No example yet
getThreads
Example 1:
/**
* Following code returns the threads of two forums having replies
* Threads are ordered alphabetically
*/
$forums = array(5, 6);
$query_options = array(
'order_by' => 't.subject',
'order_dir' => 'ASC'
);
$threads = $MyBBI->getThreads($forums, '*', 't.replies > 0', $query_options, true, true, false);
foreach ($threads as $thread)
{
echo $thread['subject'].'<br />';
}
incViews
Example 1:
$MyBBI->incViews(2);
openThread
- No example yet
removeThread
- No example yet
updateThread
- No example yet