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 CRUD Operations with PHP Reading and Writing Reports Filtering by Project

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

[SOLVED] Problem with project filter offset notice

Hi all,

So I've been at this video for about an hour following along but I can't seem to find what the problem is.

Section 3 video video 3... We've added the form that allows you to group reports but I've got this notice above the empty report that says,

Notice: Undefined offset: 1 in C:\xampp\htdocs\using_crud\inc\functions.php on line 52

I think it has something to do with the emplode function, somehow it's not passing across the colon delimiter?

I've pushed all the latest files onto my GitHub repo if someone would like to clone and take a look? If anything it'd help me learn the pull request process.

https://github.com/jg-digital-media/using_crud

Help :blush:

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Okay, well I've worked it out with a bit of sleep, some painstaking research and video backtracking.

I was so sure that I'd followed the video to the letter but there was just one or 2 little differences in my code that caused the bugs.

The first thing was I needed include the colon in my first echo string for the option value. I'm not sure what makes that work but I think it's something to do with the query string. Not having it meant a property wasn't carried over causing the offset warning.

<?php

    foreach (get_project_list() as $option) {
          echo '<option value="project:"' . $option['project_id'] . '">';
          echo $option['title'] . "</option>\n";
    }

?>

But having solved that the report wasn't generating any tasks or totla when I tested the drop down. With a keen eye, I noticed that the query string wasn't carrying a last number in the URL.

I traced the problem to the same function. One of the things about working with soft and hard quotes is knowing when to use them and in what combination. It seems like I trying to apply a hard quote into the reference to the project ID even though this was concatenated in.

<?php

    foreach (get_project_list() as $option) {
        echo '<option value="project:' . $option['project_id'] . '">';
        echo $option['title'] . "</option>\n";
    }

?>

All working now. And I hope this helps somebody someday :)