Need help with Undefined variable

Hi,

I'm trying to fix an existing script (not my code).
I'm getting Undefined variable: event_info

Here is the script part of the code:
Let me know if you need other part of the code.
Thanks


/* 
* Format events data 
*/ 
$event_info = NULL; // clear the variable 
if ( isset($events[$c]) ) 
{ 
foreach ( $events[$c] as $event ) 
{ 
$link = '<a href="view.php?event_id=' 
. $event->id . '">' . $event->title 
. '</a>'; 
$event_info .= "\n\t\t\t$link"; 
} 
} 
$date = sprintf("\n\t\t\t<strong>%02d</strong>",$c++); 
}
else { $date="&nbsp;"; } 


/* 
* Assemble the pieces into a finished item 
*/ 
$html .= $ls . $date . $event_info . $le . $wrap;
} 

Open in new window

LVL 29
lenamtlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zappafan2k2Commented:
It should be giving you a line number along with the error/warning.  What line is causing it?
0
lenamtlAuthor Commented:
This is the related line:

$html .= $ls . $date . $event_info . $le . $wrap;

With the warning there is a call stack related to the index.php do you need the index code too?
0
GaryCommented:
There is missing code, you have two closing curly's when there is no opening curly's.
I suspect you are setting the var inside one of those opening curly's so it does not exist unless whatever other code you have is processed.
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Ray PaseurCommented:
This question gives us an object lesson in the value of coding standards.  If you use consistent line-up and indent each control structure, errors like this will jump off the page!  See AntiPHPractice #7.

Counting the control structure curly braces from the bottom leads us to think that there are at least two missing conditionals or iterators at the top of the code snippet.  The NULL assignment of $event_info is two-deep inside those conditionals or iterators.  The message comes from using $event_info one-deep inside the conditionals or iterators.

Here is how we can know that, using indenting to show the control structures.

        /* 
        * Format events data 
        */ 
        $event_info = NULL; // clear the variable 
        if ( isset($events[$c]) ) 
        { 
            foreach ( $events[$c] as $event ) 
            { 
                $link = '<a href="view.php?event_id=' 
                . $event->id . '">' . $event->title 
                . '</a>'; 
                $event_info .= "\n\t\t\t$link"; 
            } 
        } 

        $date = sprintf("\n\t\t\t<strong>%02d</strong>",$c++); 
    }
    else { $date="&nbsp;"; } 


    /* 
    * Assemble the pieces into a finished item 
    */ 
    $html .= $ls . $date . $event_info . $le . $wrap;
} 

Open in new window

0
lenamtlAuthor Commented:
Like I said this is not my code, I just want to fix an existing code.
I have skipped extra lines of code...

Here is the entire page see attached file.

To see the original source code that came with the book
(the package is not complete and have issues)
http://www.apress.com/9781430228479
class.calendar.inc.php
0
Ray PaseurCommented:
I just want to fix an existing code.
We would love to help you, but the code snippet posted with the question is a fragment.  It is missing the important part.  Please check the explanation and code here.
0
Ray PaseurCommented:
This statement is the first of many giant red warning flags:

class Calendar extends DB_Connect

Nobody with any application design experience would write that!

Throw that book and the code sample into the garbage right now!  This article can help you find some good learning resources.  And I guarantee you that they will also help you understand the value of coding standards!
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
lenamtlAuthor Commented:
I have uploaded the entire page see my previous message.
0
Ray PaseurCommented:
Yes, I see the link to the code, and I looked at it, and I do not think this mess is worth fixing.  It's a terrible example and not one you should waste your time studying.  

If you want to learn PHP, try this book instead.
http://www.amazon.com/PHP-MySQL-Web-Development-Edition/dp/0321833899

If you want to learn jQuery, try this.
http://www.amazon.com/Learning-jQuery-Interaction-Development-JavaScript/dp/1847192505/
http://learn.jquery.com/
0
lenamtlAuthor Commented:
This book is probably not perfect, I agree,
There was interresting subject & approach in the book.

Thanks for the book suggestion, but for now I just want to fix the bug.
0
Ray PaseurCommented:
Not perfect is an understatement!

I'll be glad to help you fix the bug, but I'm not going to work on that unstructured 300+ line code sample.  If you will go through it and indent the control structures so they line up accurately, then post the code in the code snippet here, I'll be glad to help.

Or you can just add this line to the top of the script:

error_reporting(E_ALL ^ E_NOTICE);
0
lenamtlAuthor Commented:
I've requested that this question be deleted for the following reason:

I will try to find help elsewhere
0
GaryCommented:
In the code you posted look for
public function buildCalendar()
{


And add in after that opening curly

$event_info = NULL;

This is a quick hack
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lenamtlAuthor Commented:
Thanks a lot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.