HI all, would really appreciate some help.
PLease be gentle, this is my first attempt at programming since the 80's (and that was VB basic! :confused: )
I am using tikiwiki to set up a site. I have modified (butchered?) some existing code to create a new module.
It should return a link to a blog, however it returns "Array".
The module is in 3 parts 1) the function 2) assigning to smarty 3) Smarty. Here is the code:
// Returns the name of "n" random blogs
function get_random_blogs($n) {
$query = "select count(*) from `tiki_blogs`";
$cant = $this->getOne($query,array());
// Adjust the limit if there are not enough pages
if ($cant < $n)
$n = $cant;
// Now that we know the number of pages to pick select `n` random positions from `0` to cant
$positions = array();
for ($i = 0; $i < $n; $i++) {
$pick = rand(0, $cant - 1);
if (!in_array($pick, $positions))
$positions[] = $pick;
}
// Now that we have the positions we just build the data
$ret = array();
$temp_max = count($positions);
for ($i = 0; $i < $temp_max; $i++) {
$index = $positions[$i];
$query = "select `blogId` from `tiki_blogs`";
$name = $this->getOne($query,array(),1,$index);
$ret[] = $name;
}
return $ret;
}
Then to assign the function to smarty:
<?php
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
header("location: index.php");
exit;
}
$n = $tikilib->get_random_blogs($module_rows);
$smarty->assign('modRandomBlogs', $n);
?>
And finally the smarty code:
{* $Header: /cvsroot/tikiwiki/tiki/templates/modules/mod-random_blogs.tpl,v 1.5.10.2 2005/02/23 15:10:56 michael_davey Exp $ *}
{if $feature_wiki eq 'y'}
{tikimodule title="{tr}Correct A Blog{/tr}" name="random_blogs" flip=$module_params.flip decorations=$module_params.decorations}
<table border="0" cellpadding="0" cellspacing="0">
{section name=ix loop=$modRandomBlogs}
<tr><td class="module"><a class="linkmodule" href="tiki-view_blog.php?page={$modRandomBlogs [ix].blogId}">{$modRandomBlogs [ix].title}</a></td></tr>
{/section}
</table>
{/tikimodule}
{/if}
Any advice greatly appreciated.
Cheers
Paddyboy