Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to use PHP isset and foreach?

Posted on 2014-12-05
1
Medium Priority
?
132 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 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