Search code examples
phphtmldynamic-links

generating links dynamically


so i guess this is pretty easy for most of you, but i can't figure this out.

im trying to make the links dynamic eg: href="linkname(#1 or #2 etc)"

any ideas?

 <?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
        <?php foreach ($top_fundraisers as $index => $fundraiser): ?>
           <a title="" class="fancybox" href="linkname(GENERATE CODE HERE)">
        <div class="top-fundraiser">

            <div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
              <img src="<?php
          if($fundraiser['member_pic_medium']) {
                  print htmlentities($fundraiser['member_pic_medium']);
          } else {
            print $template_dir . '/images/portrait_placeholder.png';
          }
              ?>"/>
            </div>
    </div>
    </a>
        <?php endforeach;?>
    <?php endif; ?>

Solution

  • Suppose below is what you need.

     <?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
            <?php foreach ($top_fundraisers as $index => $fundraiser): ?>
               <a title="" class="fancybox" href="linkname(#<?php echo $index + 1; ?>)">
            <div class="top-fundraiser">
    
                <div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
                  <img src="<?php
              if($fundraiser['member_pic_medium']) {
                      print htmlentities($fundraiser['member_pic_medium']);
              } else {
                print $template_dir . '/images/portrait_placeholder.png';
              }
                  ?>"/>
                </div>
        </div>
        </a>
            <?php endforeach;?>
        <?php endif; ?>