HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Trying to make my new block simpler but not sure how exactly.

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#21472 (In Topic #5173)

Fan in action

I have at the moment:

Code (php)

$random = mt_rand(1,1);

     if ($random == "1") {
      $var_picture_large_source = "{$databank_large['001']}";
      $var_picture_small_source = "{$databank_small['001']}";
      $var_picture_caption = "{$databank_caption['001']}";
      $var_settings_target = "{$databank_target['001']}";
      $var_settings_border = "{$databank_border['001']}";
      $var_settings_title = "{$databank_title['001']}";
     }

And my block would use over 100 images so you can just imagine how many lines the "if random ==" stuff alone would take…

I thought of using something like:

Code (php)

     $random = mt_rand(1,10);

      $var_picture_large_source = "{$databank_large['{$random}']}";
      $var_picture_small_source = "{$databank_small['{$random}']}";
      $var_picture_caption      = "{$databank_caption['{$random}']}";
      $var_settings_target      = "{$databank_target['{$random}']}";
      $var_settings_border      = "{$databank_border['{$random}']}";
      $var_settings_title       = "{$databank_title['{$random}']}";
 

But I keep getting a undefined index error for "{$random}" which is somewhat frustrating cause ITS DEFINED RIGHT THERE!!!!!!! :@ :lol:
I tried removing the first {'s and the final }'s but that did not do anything conscructive (still undefined index "{$random}")

basically tried from:

Code (php)

$var_picture_large_source = "{$databank_large['{$random}']}";
to

Code (php)

$var_picture_large_source = $databank_large['{$random}'];

When random picks 1, it would/should get this stuff from a file which is include()'d, so far I have 1 thru 30 done.

Code (php)

$databank_large['1']     = "games/large/1001.jpg";
 $databank_small['1']     = "games/small/1001.jpg";
 $databank_caption['1']     = "Feel the power of the dark side!";
 $databank_target['1']    = "_Blank";
 $databank_border['1']    = "0";
 $databank_title['1']        = "Databank Gameplay Image";
 

ocProducts :wub: :wub:

Click here to drop by my website!
Back to the top
 
Posted
Rating:
#21475
Avatar

Code (php)

$random = mt_rand(1,1);
$var_picture_large_source = "{$databank_large['{$random}']}";
..
 

->

Code (php)

$random = strval(mt_rand(1,1));
$var_picture_large_source = "{$databank_large[$random]}";
..
 

I think that'll work.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#21486

Fan in action

Works very nicely, thank you :)

ocProducts :wub: :wub:

Click here to drop by my website!
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: