?
Solved

How to use PHP isset and foreach?

Posted on 2014-12-05
1
Medium Priority
?
112 Views
Last Modified: 2015-01-12
This code gives me the PDF button link. I need to replicate it for a Word button link to go next to it.

The variable for the word is field_word_document_upload

The PDF variable I'm using here is field_upload

(not concerned about the CSS right now, just trying to understand how to modify it to accommodate the second button link)

  <?php if (isset($content['field_upload']['#items'])): ?>
  <div class="list-right">
    <?php foreach($content['field_upload']['#items'] as $downloads): ?>
    <div class="resultTools"><div class="label-text"><span>Downloads: </span><span class="label-text"><?php print $downloads['download_count']; ?></span></div>
      <div class="rtTop">
        <a href="<?php print file_create_url($downloads['uri']); ?>" title="Bookmark" target="_blank" class="btn btn-sm btn-danger">
          <span class=" fa fa-file-pdf-o"></span>
          <span class="icon-text">Download<span class="grid-hide"> PDF Format</span></span>
        </a>
        <!-- file_create_url(uri) -->
      </div>
    <?php endforeach; ?>
    </div>
  </div>
  <?php endif; ?>
</div>
<?php
else:
?>

Open in new window

pdf.PNG
word.PNG
0
Comment
Question by:sandshakimi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1500 total points
ID: 40484710
so, you may add this behind: ?

  <?php if (isset($content['ield_word_document_upload']['#items']))  ?>
  <div class="list-right">
    <?php foreach($content['ield_word_document_upload']['#items'] as $downloads): ?>
    <div class="resultTools"><div class="label-text"><span>Downloads: </span><span class="label-text"><?php print $downloads['download_count']; ?></span></div>
      <div class="rtTop">
        <a href="<?php print file_create_url($downloads['uri']); ?>" title="Bookmark" target="_blank" class="btn btn-sm btn-danger">
          <span class=" fa fa-file-doc-o"></span>
          <span class="icon-text">Download<span class="grid-hide"> DOC Format</span></span>
        </a>
        <!-- file_create_url(uri) -->
      </div>
    <?php endforeach; ?>
    </div>
  </div>
  <?php endif; ?>
</div>
           

Open in new window

note sure if the listing shall have both links next to each other or not...
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question