Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Need examples of using nuDebug to display values

Locked
JohnKlassen
Posts: 148
Joined: Wed Dec 05, 2012 4:56 am

Need examples of using nuDebug to display values

Unread post by JohnKlassen »

Hi,

I am creating some reports that require some extra logic including determining the number of days between a date in a row and today. In order to debug my logic, I want to use nuDebug. I have gone through every reference to nuDebug in the forum, wiki and the video tutorials and I am still confused on how to use nuDebug. Can you give some examples of how I would display values? Normally I would use 'echo' but than is not an option.

For example, once I select some records and load them into #dataTable#, I want to calculate the number of days between the date defined in the row and today. I think the command to calculate age would be the following:
$age = DATEDIFF(NOW(), 'date_entered')
What I want to know is how do I set up a loop to process all of the rows in #dataTable# and secondly, how do I display the value of $age (above) for each row using nuDebug.

I do understand that the output of nuDebug is in the zzsys_trap table.

I appreciate your help.

John
admin
Site Admin
Posts: 2824
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 29 times

Re: Need examples of using nuDebug to display values

Unread post by admin »

John,

You shouldn't have to loop through your #dataTable#.

Code: Select all


CREATE TABLE #dataTable# SELECT transaction.*, DATEDIFF(NOW(), tra_date) AS thedays FROM transaction

So you now have a table with all of transaction and an extra field called thedays.

Steven
JohnKlassen
Posts: 148
Joined: Wed Dec 05, 2012 4:56 am

Re: Need examples of using nuDebug to display values

Unread post by JohnKlassen »

Steven,

Thanks for the code suggestion. It worked great.

But... I still need to understand how to debug my code. Most of the code I need to write is either going into the 'PHP Code' section for a report or I will use it in a form. If I am writing it for a report, I want to display the values of various fields to test whether I am doing it right. With the example you gave me it is easy to test because all I have to do is display the value of 'thedays' in my report. But this report and several more like it get more complicated. The row in the table has 5 date fields: date_1 through date_5. These date fields are used to track when notices are sent out to a tenant. There will always be a value in date_1 but there may not be a value in any of the other date fields. On the other hand, if there is a value in, for example, date_4, there will also be a value in date-1 through date_3. In addition to calculating the number of days from today to date_1, I also need to determine which is the most recent date in the 5 date fields and calculate the numbers of days for that date field.

I was thinking of using some 'If, Then' logic or CASE logic to determine the most recent date. For this reason and for other planned logic in other reports, I was hoping to get an example of how I could loop through a table.

I also wanted examples of how to use nuDebug. In a report scenario, the only place I can display values while testing is in the actual report. nuDebug offers an alternative.

I thought of doing my testing by writing a PHP script, storing it in webroot and then running the script in a browser. That way I can use 'echo'. The problem there is how to get the php script to use nuBuilder functions such as nuRunQuery, etc.

So... I would appreciate any suggestions you have on testing. I would also appreciate any examples of using nuDebug.

Thanks,

John
admin
Site Admin
Posts: 2824
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 29 times

Re: Need examples of using nuDebug to display values

Unread post by admin »

John,

A simple loop through a table might look like this...

Doing this in an Activity Procedure will mean you can just echo results to the screen.

If you use nuDebug($r->tranasction_id) your parameter will be stored in the zzsys_trap table in the field called tra_message.

Code: Select all



$s = CREATE TABLE #dataTable# SELECT * FROM transaction";
$t = nuRunQuery($s);

while($r = db_fetch_object($t)){

   $sql = UPDATE #dataTable# SET tra_total = $r->tra_amount + $r->tra_tax WHERE transaction_id = 'transaction_id'";

   nuRunQuery($sql);


}



Steven
JohnKlassen
Posts: 148
Joined: Wed Dec 05, 2012 4:56 am

Re: Need examples of using nuDebug to display values

Unread post by JohnKlassen »

Steven,

Thank-you. This is exactly what I was looking for. A place to practice PHP and SQL and get immediate feedback through echo and nuDebug().

John
admin
Site Admin
Posts: 2824
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 29 times

Re: Need examples of using nuDebug to display values

Unread post by admin »

my pleasure.
Locked