Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

dandrew Merriweather
dandrew Merriweather
1,864 Points

No return from code

Don't know why i'm getting errors with this code.

 <?php
        //this is the description of each area containing PDFs
        $living = get_field( "living_desc" );

        //this checks is the row has data
        if( have_rows('living_skill') ):

            //this is a repeater in a while loop
            while ( have_rows('living_skill') ) : the_row();

                //these are sub fields
                $title   = get_sub_field('title');
                $file    = get_sub_field('file');

            ?>
                <p><?php echo $title ?></p>
                <p><?php echo $file ?></p>


                <?php
Simon Coates
Simon Coates
28,694 Points

This doesn't seem related to any given challenge, so we might need more information to do any kind of debugging (what is the error exactly?). At a quick glance, i can't see anything too wrong with it, apart from being a fragment (hence not using $living, featuring endif, endwhile). I assume this is wordpress (a theme?). At risk of stating the obvious can you not echo and var_dump to trace the flow and variable values, and narrow down the bug to a specific point. so test the value of living, test that your getting in the if, then put an output in the while to confirm getting in there, and confirm the row is what you think it is. Systematically check your assumptions. If your code is solid, then maybe you don't have access to something you thought you did.

1 Answer

dandrew Merriweather
dandrew Merriweather
1,864 Points

Yes you are correct i'm pretty new, creating customs templets using php and word press, but yea having trouble echoing title as well as file

Simon Coates
Simon Coates
28,694 Points

If the code is getting inside the if condition and the while loop, then use var_dump to take a look at the row. something like $row = get_row(); should get the row (try to confirm data structure is consistent with the sub field names you're using). If you're not getting inside if, or while at all, then your problem is earlier.