Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

How do I fill a field in #dataTable# with underscores

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

How do I fill a field in #dataTable# with underscores

Unread post by JohnKlassen »

Hi,

I have a 1 page report that has about 40 fields in it. I select the original data from various tables and create #dataTable#. Since I have to use some logic to manipulate the data in #dataTable# before using it in the report, I have added many of these 40 fields to #dataTable# and have created corresponding variables for those 40 fields.

As I read the rows in #dataTable#, I check to see if the column has data. If it has data, I copy the data to the variable. If the column is empty, I want to fill the variable with underscores so it shows as an underline in the report wherever there is no data. I have tried the following code, which works fine:

Code: Select all

     if (!empty($row->peo_company))  
     	$own_company = $row->peo_company;
          else
	  $own_company = '_____________________________';
As you can see I check to see if 'peo_company' is empty or not. If it is not empty, I move the contents from the column to the variable '$own_company'. If the column is empty, I fill the variable '$own_company' with underscores. Although this code works, it means I have to carefully figure out how many underscores to put into the variable.

The only other option I could find was to fill the variable with underscores using LPAD or RPAD. I tried the following code but there must be something wrong with it because, it will no longer create the report.

Code: Select all

     if (!empty($row->peo_company))  
   	$own_company = $row->peo_company;
  else
	  $own_company = RPAD('_', 25, '_');
I need to have someone tell me what is wrong with the syntax for RPAD (or LPAD) or offer an alternative. The research I have done on RPAD and LPAD always has examples using a SELECT statement. Can I not use RPAD or LPAD in my example?

Thanks,

John
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: How do I fill a field in #dataTable# with underscores

Unread post by massiws »

John, RPAD/LPAD are SQL functions; inside PHP code you have to use PHP functions, like str_repeat():

Code: Select all

$own_company = !empty($row->peo_company) ? $row->peo_company : str_repeat('_', 25);
Max
JohnKlassen
Posts: 148
Joined: Wed Dec 05, 2012 4:56 am

Re: How do I fill a field in #dataTable# with underscores

Unread post by JohnKlassen »

Max,

Thanks for explaining that I needed to use PHP code instead of SQL code. Your example works really well and saves me a lot of code.

Thanks again.

John
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: How do I fill a field in #dataTable# with underscores

Unread post by massiws »

.
Locked