What custom code to use?

chriso0258 26 Jun, 2015
Hello,

I'm trying to display some records from a db reader. I can get the information sent by the $form->data array to print by using the { }, for example,
<td>{eastList.state_tag}</td>
However, when I use this method to print what the db reader pulls up, all I get is what you see in the picture
[attachment=0]output1.jpg[/attachment]

What would be the correct way to write the custom code for the data from the db reader?

Thanks for your assistance.

Below is the debug info:
Array
(
    [cont] => lists
    [ccname] => eastEquipList
    [act] => edit
    [gcb] => 1
    [eastList] => Array
        (
            [its_equip_id] => 1
            [state_tag] => J70141
            [region_equip] => 1
            [site_equip] => 1
            [type] => Printer
            [brand] => LEXMARK
            [model] => Z52
            [serial_no] => 9330415007
            [memory] => 
            [prod_key] => 
            [purch_date] => 
            [warr_date] => 
            [surplus_date] => 
        )

    [location] => Array
        (
            [0] => Array
                (
                    [its_location_id] => 1
                    [state_tag_loc] => 1
                    [status_loc] => 3
                    [region_loc] => 1
                    [site_loc] => 1
                    [building] => B2
                    [room] => MAILROOM
                    [dated_entered] => 3/16/2015
                    [date_moved] => 
                    [staff_id_loc] => 1
                )

            [1] => Array
                (
                    [its_location_id] => 51
                    [state_tag_loc] => 1
                    [status_loc] => 1
                    [region_loc] => 1
                    [site_loc] => 1
                    [building] => A
                    [room] => AC-101
                    [dated_entered] => 6/19/2015
                    [date_moved] => 6/19/2015
                    [staff_id_loc] => 1
                )
        )
)
GreyHead 27 Jun, 2015
Hi chriso0258,

You can use {location.0.its_location_id} . . . {location.1.its_location_id} but that is tedious and assumes you know how many records you will have.

Or you use a PHP loop:
<table>
  <thead>
    <tr>
      <th> . . .</th>
      . . .
   </tr>
  </thead>
  <tbody>
<?php
foreach ( $form->data['location'] as $l ) {
  echo"
<tr>
  <td>{$l['its_location_id']}</td>
  . . .
</tr>
  ";
}
?>
  </tbody>
</table>

Bob
chriso0258 29 Jun, 2015
Hello Bob, Your suggestion worked well as you can see in the picture.
[attachment=0]output1.jpg[/attachment]
Notice that there is a number in the Status, Region, Site, and Staff columns. These columns are foreign keys to their respective tables.

When I make a join in the db reader the data disappears (which doesn't surprise me) as shown in the next picture.[attachment=1]output2.jpg[/attachment]

Each column in the relationship is it's own array as you can see in the debug data below. What is the best way to write the code so that, for example in the Status column it shows "Standalone" instead of a 3 (which is what a 3 is in the status table), East in the Regions column, BCCX in the site's column, Mickey Mouse for the Staff column.

Thanks for your help with this.

Array
(
    [cont] => lists
    [ccname] => eastEquipList
    [act] => edit
    [gcb] => 2
    [eastList] => Array
        (
            [its_equip_id] => 2
            [state_tag] => J70145
            [region_equip] => 1
            [site_equip] => 1
            [type] => Printer
            [brand] => LEXMARK
            [model] => Z52
            [serial_no] => 9330415017
            [memory] => 
            [prod_key] => 
            [purch_date] => 
            [warr_date] => 
            [surplus_date] => 
        )

    [0] => Array
        (
            [location] => Array
                (
                    [its_location_id] => 2
                    [state_tag_loc] => 2
                    [status_loc] => 3
                    [region_loc] => 1
                    [site_loc] => 1
                    [building] => Unit 02
                    [room] => COUNSELOR 
                    [dated_entered] => 3/16/2015
                    [date_moved] => 
                    [staff_id_loc] => 1
                )

            [status] => Array
                (
                    [equip_status_id] => 3
                    [status] => Standalone
                )

            [regions] => Array
                (
                    [region_id] => 1
                    [region] => East
                )

            [site] => Array
                (
                    [site_id] => 1
                    [region_sites] => 1
                    [site] => BCCX
                )

            [staff_id] => Array
                (
                    [staff_id] => 1
                    [bi_no] => bi01d35
                    [name] => Mickey Mouse
                    [region_staff] => 1
                )
        )
)
chriso0258 29 Jun, 2015
Hello Bob,

I figured out how to do this but kept getting parts of the cont, ccname, act, and gcb arrays as you can see in the picture below:
[attachment=0]output1.jpg[/attachment]

I fixed this with the following code by checking to see if the $key was numeric or not.

Thanks for putting me on the right trail Bob!! BTW, if there is a better way of iterating through this array or writing the code, please let me know as I always want to do things better.

Chess Dad.

<?php
foreach ($form->data as $key => $x) {
if (is_numeric ($key)) {
  echo"
    <tr>
           <td>
                 {$x['status']['status']}
	   </td>
	   <td>
			{$x['region']['region']}
	   </td>
	   <td>
			{$x['site']['site']}
	   </td>
	   <td>
			{$x['building']['building']}
	   </td>
	   <td>
			{$x['location']['room']}
	   </td><td>
			{$x['location']['date_moved']}
	   </td><td>
			{$x['staff']['name']}
	   </td><td>
			{$x['location']['dated_entered']}
	   </td>
    </tr>
";
}}
?>
This topic is locked and no more replies can be posted.