Alexander Levenetz <[EMAIL PROTECTED]> said: 

> Alan,
> 
> 
> > Sounds like an A level maths question :)
> 
> ROTFL!
> 
> > One way of doing it - off the top of my head
> 
> Ahh, what kind of a head do you have?! ;-)
> 
> > 1. build an an array of the available articles
> > $o = mgd_list_topic_articles(x)
> > $a = array();
> while ($o->>fetch()) $a[]= $o->id;
> 

this builds an array of available article ids in $a

eg. a would end up with
a[0] = 34
a[1] = 35
a[2] = 36
. you could expand the logic here to include the conditions below on whether
and 

> Maybe I should give up...
> 
> > 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";
> > }
> 

> Ok, I couldn't say that this looks great to me as I don't understand
> anything here... Oh, wait, there is a four! :-) = four articles
> displayed?

this takes the array of available articles and builds an assoicative array of
articles to display in $b - based on a random number. and maxes out at 4 items
$b[34] = "USEME";
$b[32] = "USEME";
$b[33] = "USEME";
..

> 
> > 3. print them
> > while (list($k,v) = each($b)) {
> >   mgd_get_article($k)
> >  // print it!
> > }
> 

> Would that print all of them? Or just 4?
> Would I put this whole list that way into my script? I.e. instead of
> my old

since there should only be 4 articles in $b (actually It may need a bit of
fine tuning as I think counting associate arrays is a bit flakey)

> 
> > <?
> >  $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++;
> > ?>
> 
> ?
> Where would I then put this part

in 2 (where the $a[] = $o->id ) = $o = $article
> 
> >    if (mgd_is_article_in_topic_tree(94, $article->id)) { continue; }
> 
> ?
> This is well beyond my comprehension, I must say :-( Thanks for your
> patience!
> 

I would suggest playing with the code, try printing stuff as it goes along to
see what is happening, remember that $o is an object so you cant print $o, but
you can print $o->title, $o->id etc.

regards

alan


> Alexander
> 
> 
> 
> ---------------------------------------------------------------------
> 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]

Reply via email to