Solved

PHP foreach List

Posted on 2014-11-09
2
243 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now