Posted on: 04/09/04 12:19pm
By: dgaussin
I would like to do a random block and I don't know how I could success with that
The idea is following. I have always on my page a block at the same place but each times it's displayed, it's another block content displayed. Sometimes it's the user of the month, a photo from gallery another time, a tip of the day another time yet.
Hope it was clear
David.
Random block
Posted on: 04/09/04 01:17pm
By: Turias
Do you know php? Do you at least have php functions for each random block you would like to display?
Random block
Posted on: 04/09/04 01:27pm
By: dgaussin
Before to write it myself, I hoped maybe someone has a good and simple idea to do it, or even better, someone has already a block to do it
David.
Random block
Posted on: 04/09/04 01:40pm
By: Turias
Well, it sounds easy enough. Just write the X functions you want. Then, write a block like this:
function phpblock_randomBlock()
{
$i = rand(1, 3);
switch ($i)
{
case 1:
return phpblock_function1();
case 2:
return phpblock_function2();
case 3:
return phpblock_function3();
}
}
Hope that helps!
Random block
Posted on: 04/09/04 02:13pm
By: dgaussin
Oh yes, it very helps. It's a good skeleton to start, I know what to do now..
Thanks,
David.
Random block
Posted on: 01/11/06 10:31pm
By: Anonymous (MaxPower)
I type this code in to my lib-custom.php file, and get the following error:
Parse error: parse error, unexpected $ in /home/wetcol81/public_html/blog/system/lib-custom.php on line 405
What am I doing wrong?
Thanks!
Random block
Posted on: 02/01/06 08:11am
By: 1000ideen
It would be nice if dgaussin could post the end result if there is any. By chance I am also looking for a random block as follows: (BUT I definitely know nothing about php I just started learning css... I had a look at those random blocks of galeries but I really don`t get it.)
Mambo got a nice feature of "news flashes". It is no more than a block that displays the story text of a story witin a certain topic.
E.g. if there is a topic news_flashes the block shows the storytext or rather just {story_introtext} (or e.g. just the picture included) of one of the stories within topic news_flashes.
So the overall structure would be: Count the number of stories in topic news_flashes, choose one of them, display {story_introtext}
Anybody accidentally about to build such a block???
Random block
Posted on: 02/03/06 06:21pm
By: machinari
[QUOTE BY= 1000ideen]
So the overall structure would be: Count the number of stories in topic news_flashes, choose one of them, display {story_introtext}
Anybody accidentally about to build such a block???
[/QUOTE]
function phpblock_randomStory()
{
global $_TABLES, $_CONF;
$result = DB_query("SELECT sid,tid,title,introtext FROM {$_TABLES['stories']}
WHERE (draft_flag = 0) AND (date <= NOW())"
. COM_getPermSQL ('AND') . " ORDER BY RAND LIMIT 1");
if( DB_numRows($result) > 0 ){
$A = DB_fetchArray( $result );
$retval = '<a href="' . COM_buildUrl( $_CONF['site_url']
. '/article.php?story=' . $A['sid'] ) . '">'
. COM_stripslashes($A['title'])
. '</a> (' . $A['hits'] . ')<br>';
$retval .= '<div class="introtext">' . COM_stripslashes($A['introtext']) . '</div>';
return $retval;
}
}
something like that I think