Solved

PHP foreach List

Posted on 2014-11-09
2
240 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
Comment Utility
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
Comment Utility
Perfect, thanks for the help!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

772 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

11 Experts available now in Live!

Get 1:1 Help Now