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 trialAmber Stevens
Treehouse Project Reviewercan't figure out a loop that works
I have an edit.php page with a form on it that pulls the selected journal entry up for edit. So what I'm TRYING to do is get the form to automatically fill in the data for the links that are already in the database for that page (which I was able to do successfully) and THEN add empty input areas for adding links IF that page has less than 3 links (I'm trying to allow for all pages to store a max of 3 links (so for instance if a page currently only has one link associated with it then I'd want that link to be listed first and then 2 empty inputs or whatever) Here's what I have:
$i = 0;
while($i < 3) {
foreach($resources as $link) {
if($link['journal_id'] == $get_id['journal_id']) {
echo '<label for="link_name">Enter name for link:</label>';
echo '<input id="link_name" type="text" name="link_name" value="' .$link["link_name"] .'">';
echo '<label for="link_address">Enter web link here:</label>';
echo '<input id="link_address" type="text" name="link_address" value="' .$link['link_address'] .'">';
$i++;
}
}
if($i < 3) {
echo '<label for="link_name">Enter name for link:</label>';
echo '<input id="link_name" type="text" name="link_name[]">';
echo '<label for="link_address">Enter web link here:</label>';
echo '<input id="link_address" type="text" name="link_address[]">';
$i++;
}
}
```?>
I've tried all sorts of different loops, and loops within loops etc. Can't seem to figure this one out! Any help would be appreciated.