Solved

PHP foreach List

Posted on 2014-11-09
2
246 Views
Last Modified: 2014-11-09
Hi,

Looking for some help with my PHP foreach loop below.

I currently have the below working on my website which displays a list of information (title and some text information next to it for each row) in my concrete5 site.

<?php
$attr_set = AttributeSet::getByHandle('projects');
$attr_keys = $attr_set->getAttributeKeys();
?>
<ul id="projectList" class="list-alignLeft">
<?php foreach($attr_keys as $ak) { ?>
<li class="projectLabel"><?= $ak->akName ?></li>
<li class="projectInfo"><?= $c->getAttribute($ak->akHandle) ?></li>
<?php } ?>
</ul>

Open in new window


I would like to test the $ak->akHandle variable to see if its empty then omit that row (and the title next to it) from the list of data if empty.

I would also like to see if the last variable in the array (project_link) has data then make it a link if so.

Could someone please help with the above.

Many thanks.
0
Comment
Question by:JiveMedia
[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
2 Comments
 
LVL 10

Accepted Solution

by:
aboo_s earned 500 total points
ID: 40431966
foreach($attr_keys as $ak)
this already deals with rows that exist (not empty) unless you mean some other thing when you say empty.
anyway you can do this
if(strlen($c->getAttribute($ak->akHandle))>0)
{
echo ..
}
0
 

Author Closing Comment

by:JiveMedia
ID: 40432050
Perfect, thanks for the help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Knowledge base software has turned out to be a quite reliable method for storing information, promoting collaborative work and for sharing valuable input and solutions.However, some organizations are trying to develop a knowledge base that works wit…
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to count occurrences of each item in an array.

734 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