Alexander Levenetz <[EMAIL PROTECTED]> said:
> Hello,
>
> I use
>
> <?
> $article = mgd_list_topic_articles_all($topic_id); {
> $displayed = 0;
> while ($displayed < 4 && $article && $article->fetch()) {
> if (mgd_is_article_in_topic_tree(94, $article->id)) { continue; }
> if (mgd_is_article_in_topic_tree(111, $article->id)) { continue; }
> $displayed++;
> ?>
>
> to display the 4 most recent articles of a certain topic.
> How can I make this work that way (a seperate script!), that every
> time the page is reloaded a new article (most recent article should
> not be a criteria anymore!) of a certain topic is shown at these 4
> places whereas no article should be displayed more than one time on
> the same page/refresh cycle.
> I hope this was somehow understandable... It should work like a
> placeholder for an advertisement banner that changes (out of a pool)
> every time the page is reloaded till is appears again after a while.
> Thanks!
Sounds like an A level maths question :)
One way of doing it - off the top of my head
1. build an an array of the available articles
$o = mgd_list_topic_articles(x)
$a = array();
while ($o->fetch()) $a[]= $o->id;
2. build a list of articles from that list (using random numbers?)
function randomint($max = 100) {
static $startseed = 0;
if (!$startseed) {
$startseed = (double)microtime()*getrandmax();
srand($startseed);
}
return (rand()%$max);
}
$b=array()
while (count($b)<4) {
$n = randomint(count($a));
if (!$b[$a[$n]]) $b[$a[$n]] = "USEME";
}
3. print them
while (list($k,v) = each($b)) {
mgd_get_article($k)
// print it!
}
Off the top of my head (and late at night).... - I'm sure theres other ways to
do it :)
regards
alan
>
> Alexander, who starts to like Midgard...
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
Technical Director
Linux Center (HK) Ltd.
www.hklc.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]