#1
  1. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112

    Universal Column Builder


    Well, the overall basic idea seems simple and easy. Create a single array to use as the column headers, and run a loop of the returned rows from a MySQL query to fill the table.

    Doing this independently is currently done. I want to try and build a universal class/function to pull this off, if easily possible. The catch is not the fact that the column count changes, but the fact that the content type does. There are 3-4 types. Checkbox(X), formatted currency, and text. The text differs that the 'account' text offers a drop-down when switched to 'Edit' mode, while the others are just standard text INPUT boxes. I can probably build a 'type' array to be passed along, but I feel the formatting may be a ton extra to slide in.

    Below is my current setup of 2 functions. Each build_ function is for its own page, and only 1 is ran per page. Anyone with any ideas feel free to let me know. Thanks.

    The Accounts page:
    PHP Code:
    function build_account() {
      
    $rows '      <H1>Account Management</H1>
        <DIV class="table">' 
    "\n";
      if(
    $_SESSION['mode'] == 'edit') {
        
    $rows .= '        <FORM class="tr">
            <SPAN class="td"><INPUT name="active" type="checkbox" checked /></SPAN>
            <SPAN class="td"><INPUT name="name" /></SPAN>
            <SPAN class="action td"><IMG class="add" src="./img/add.png" /></SPAN>
          </FORM>' 
    "\n";
      }
      
    $rows .= '        <DIV class="tr"><SPAN class="th">Status</SPAN><SPAN class="th">Account Name</SPAN></DIV>' "\n";
      
    $link = new Connection();
      
    $db $link->openDB();
      
    $stmt $db->prepare('SELECT `id`, `name`, `active` FROM `account` ORDER BY `name` ASC;');
      
    $stmt->execute();
      while(
    $row $stmt->fetch()) {
        
    $rows .= '        <FORM class="tr">
            <SPAN class="td">' 
    . ($row[2] == 'Active' 'Inactive') . '</SPAN>
            <SPAN class="td">' 
    $row[1] . '</SPAN>
            <SPAN class="action td">
              <SPAN class="row-info">
                <INPUT name="acc_id" type="hidden" value="' 
    $row[0] . '" />
              </SPAN>' 
    "\n";
        if(
    $_SESSION['mode'] == 'edit') {
          
    $rows .= '            <SPAN class="view-icons"><IMG class="edit" src="./img/edit.png" /> &nbsp; <IMG class="delete" src="./img/delete.png" /></SPAN>
            <SPAN class="edit-icons"><IMG class="save" src="./img/save.png" /> &nbsp; <IMG class="cancel" src="./img/cancel.png" /></SPAN>' 
    "\n";
        }
        
    $rows .= '          </SPAN>
            </FORM>' 
    "\n";
      }         
      
    $link->closeDB();
      
    $rows .= '      </DIV>' "\n";
      return 
    $rows;

    This builds the Balances page:
    PHP Code:
    function build_balance($year) {
      
    $edit $total NULL;
      
    $format = new NumberFormatter('en_US'NumberFormatter::CURRENCY);
      
    $rows '      <H1>Open Account Balances</H1>
        <DIV class="table">' 
    "\n";
      if(
    $_SESSION['mode'] == 'edit') {
        
    $rows .= '        <FORM class="tr">
            <SPAN class="th">
    select_account() . '<INPUT name="comment" size="10" />
            </SPAN>
            <SPAN class="th"><INPUT class="currency" name="balance" placeholder="0.00" size="5" /> / <INPUT class="currency" name="limit" placeholder="0.00" size="2" /></SPAN>
            <SPAN class="th"><INPUT class="datepicker" name="asof" placeholder="01/01" size="3" /></SPAN>
            <SPAN class="action td"><IMG class="add" src="./img/add.png" /></SPAN>
          </FORM>' 
    "\n";
      }
      
    $rows .= '        <DIV class="tr"><SPAN class="th">Account (Comment)</SPAN><SPAN class="th">Total Due / Limit</SPAN><SPAN class="th">As of...</SPAN></DIV>' "\n";
      
    $link = new Connection();
      
    $db $link->openDB();
      
    $stmt $db->prepare('SELECT t2.`name`, t1.`comment`, t1.`value`, t1.`limit`, t1.`date` FROM `balance` AS t1 LEFT JOIN `account` AS t2 ON t1.`account` = t2.`id` WHERE t1.`type` = 1;');
      
    $stmt->execute();
      while(
    $row $stmt->fetch()) {
        
    $balance $format->formatCurrency($row[2], 'USD');
        
    $comment $row[1] != NULL '(' $row[1] . ')' NULL;
        
    $date date_create($row[4]);
        
    $format->setAttribute(NumberFormatter::FRACTION_DIGITS0);
        
    $limit $row[3] != NULL '/' $format->formatCurrency($row[3], 'USD') : NULL;
        
    $format->setAttribute(NumberFormatter::FRACTION_DIGITS2);
        
    $total $total $row[2];
        
    $rows .= '          <FORM class="tr">
            <SPAN class="td">' 
    $row[0] . ' ' $comment '</SPAN>
            <SPAN class="td">' 
    $balance $limit '</SPAN>
            <SPAN class="td">' 
    date_format($date'm/d/Y') . '</SPAN>
            <SPAN class="action td">
              <SPAN class="row-info">
                <INPUT name="acc_id" type="hidden" value="' 
    $row[0] . '" />
              </SPAN>' 
    "\n";
        if(
    $_SESSION['mode'] == 'edit') {
          
    $rows .= '              <SPAN class="view-icons"><IMG class="edit" src="./img/edit.png" /> &nbsp; <IMG class="delete" src="./img/delete.png" /></SPAN>
              <SPAN class="edit-icons"><IMG class="save" src="./img/save.png" /> &nbsp; <IMG class="cancel" src="./img/cancel.png" /></SPAN>' 
    "\n";
        }
        
    $rows .= "          </SPAN>
          </FORM>\n"
    ;
      }         
      
    $link->closeDB();
      
    $rows .= '          <DIV class="tr"><SPAN class="td">&nbsp;</SPAN></DIV>' "\n";
      
    $rows .= '          <DIV class="tr"><SPAN class="td description">Total Due</SPAN><SPAN class="td">' $format->formatCurrency($total'USD') . "</SPAN></DIV>\n";
      
    $rows .= '      </DIV>' "\n";
      return 
    $rows;

    The accounts page keeps it simple and makes it look a simple idea. The Balances page has a handful of formatting where I think the difficult part may step in...
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,896
    Rep Power
    9646
    I'm not exactly clear on what you want to end up with. Can you give an example of how you intend to use this? Like, what kind of code do you want to write. That's generally how I approach a programming design problem: start at the end goal and work backwards.
  4. #3
  5. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    Well, the basic thought of the input would be 2 arrays.
    1.) A single-dimensional array defining the column titles
    2.) A multi-dimensional array containing the values for each row

    I want to be able to pass those 2 items to a universal function that will build a table. If it was as basic as just taking the input and building the tables with that data, there would be nothing to it. The issue is more the fact that some columns may be text, while others may be currency. If the data/currency items always landed in the same columns each time, that would also make it easy. The trouble is, for instance, sometimes column 2 may hold text, and sometimes currency. Since currency is stored/fetched as a 2-decimal character from the database, it needs to be formatted in a USD currency manner before being applied in its location.

    As I was writing this, I just had another thought. Instead of a single-dimensional array handed in for the column titles, make it a multi-dimensional array, with the 2nd inner dimension handing in values for column 'type'... Then, there would just be some manner of treating each value in an instance related to its 'type' as processed, since it would then have such info...
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  6. #4
  7. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,896
    Rep Power
    9646
    Storing text or currency in one column isn't great. Can you change that?

    The hard part of this is turning the table values into displayable values. I'd go with simple callbacks like
    PHP Code:
    $currency0 = new NumberFormatter("en_US"NumberFormatter::CURRENCY);
    $currency0->setAttribute(NumberFormatter::FRACTION_DIGITS0);

    $currency2 = new NumberFormatter("en_US"NumberFormatter::CURRENCY);
    $currency2->setAttribute(NumberFormatter::FRACTION_DIGITS2);

    // process a row
    $total 0;
    $format = function($row) use ($currency0$currency2, &$total) {
        
    $total += $row["value"];

        
    $row["comment"] = ($row["comment"] ? " (" $row["comment"] . ")" "");
        
    $row["value"] = ($row["value"] ? $currency2->formatCurrency($row["value"], "USD") : "");
        
    $row["limit"] = ($row["limit"] ? "/" $currency0->formatCurrency($row["limit"], "USD") : "");
        
    $row["date"] = date_create($row["date"])->format("m/d/Y");
    };

    // format for display
    $display = array(
        
    // header => function($row) { return displayable value; }
        
    "Account (Comment)" => function($row) {
            return 
    $row["name"] . $row["comment"];
        },
        
    "Total Due / Limit" => function($row) {
            return 
    $row["value"] . $row["limit"];
        },
        
    "As of..." => function($row) {
            return 
    $row["date"];
        }
    ); 
    I would pass the query as a string or resultset to the utility function, along with the two sets of callbacks. It pulls the headers from $display, then loops over the results and applies $format then $display as it goes.
    Displaying the $total at the bottom of the table is a bit unique, though, not only because it doesn't follow the columnar format.

    But please, if you're displaying tabular data then use a table. A real, actual <table>. Not DIVs and SPANs styled with CSS to behave like a table.
    Last edited by requinix; December 26th, 2017 at 02:32 AM.
  8. #5
  9. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    Well, as far as me currently using DIVs/SPANs to build this table, this is a first, and originally not a preferable act. The only reason I ended up using this structure is because every row is to have the ability to be independently editable, and its own FORM is to be applied per-row. I didn't exactly find all the best options for such using an actual TABLE.

    As far as storing values in the database, the database is built valid for the values it contains. The thing is the fact that each page/build_* function references a different table to match the requested page. So, as for the values each holds and is to be formatted, different will exist. The Accounts page only has a checkmark and account name. The Balances page is the only to contain the Limit value formatted with zero decimal.

    Now that you mention the totals at the bottom, that is one I haven't thought about. Thursday I should be free to make an attempt to build this, and have a fair idea, so I suppose we'll see how it goes. Thanks for the input.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  10. #6
  11. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,896
    Rep Power
    9646
    It doesn't look like you're using forms normally, though. If you're already requiring Javascript for editing then you can also submit edits via AJAX. But I do love telling people to completely redo everything they have for one imagined reason or another so you can ignore that part
  12. #7
  13. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    Well, the JavaScript action is more the enable/disable or switching to/from Read/Edit modes. In Read mode, each column is to simply display as intended. When switched to Edit mode, each column of a row then transforms into an editable field in relation to the item it represents. That row is wrapped in its own FORM tag. I took a quick peek in threads started by me, since I could remember bringing this up, but apparently just as a side comment somewhere. If you're interested in helping out a bit with this, I can grant you a general login to a copy of the files to get a peek.

    I know the main reason I went this way was due to the forms, but if you have a better method in mind due to my use of AJAX, I think I may be interested in that method so I can build my tables via their normal tags...

    The overall of the TR/TD vs DIV/SPAN was brought up in Possible re-order CSS designed table rows? and kicken mentioned it as a fair option as long as the form wasn't attempted to be submitted via an Enter key or such. I would just have to figure out how to keep it an AJAX item, leave other row's editable fields untouched, and have it send the update in relation to the correct row...
    Last edited by Triple_Nothing; December 26th, 2017 at 07:58 PM.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  14. #8
  15. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    Sorry for the recall of an older thread, but just curious...

    Whenever I have used functions, I have always defined them in more of a library to be call upon. In your example above, I understand the using a function to define $format, but the inner functions I'm a bit off on. I'm assuming use() is just another way to include an outer variable.

    Within the $display array, how are the following 2 items different from one another?
    PHP Code:
    "Account (Comment)" => function($row) {
        
    return $row["name"] . $row["comment"];
    }, 
    PHP Code:
    "Account (Comment)" $row["name"] . $row["comment"], 
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  16. #9
  17. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,273
    Rep Power
    4193
    Within the $display array, how are the following 2 items different from one another?
    The first defines a callback function using a closure. The second would just assign a string directly using whatever $row is at the time.

    The point of the callback is that you can apply it to any given $row value and get a desired result for that row. So the overall code would look something like:

    Code:
    // format for display
    $displayFormatters = array(
        // header => function($row) { return displayable value; }
        "Account (Comment)" => function($row) {
            return $row["name"] . $row["comment"];
        },
        "Total Due / Limit" => function($row) {
            return $row["value"] . $row["limit"];
        },
        "As of..." => function($row) {
            return $row["date"];
        }
    );  
    
    foreach ($yourData as $row){
        echo '<tr>';
        foreach ($displayFormatters as $header=>$formatter){    
            echo '<td>'.$formatter($row).'</td>';
        }
        echo '</tr>';
    }
    So for each column in your output table, you have a small function that gives you desired value for that column based on the row's data. Then you just loop over your result set and apply the appropriate function for each column to the row
    Last edited by kicken; January 3rd, 2018 at 02:29 PM.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  18. #10
  19. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    Cool. I had the right idea in mind, just wasn't quite getting the use to process correctly... Thanks.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  20. #11
  21. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    I think I've generally got this started, but think I'm totally avoiding the $format item. The tables are successfully being built, but the formatting is not being applied, and I see no reference to such.
    I've looked at a handful of callback examples/tutorials, but they don't seem to be using them in the same manner, so I am still a bit off at altering this myself. I know if I add the parenthesis around the $row['comment'] in the $display's callback, they will appear, but they are already defined above in the shorthand if/else statements.

    Test via fresh build_(page) function:
    PHP Code:
    function build_testing() {

      
    $link = new Connection();
      
    $db $link->openDB();
      
    $stmt $db->prepare('SELECT t2.`name`, t1.`comment`, t1.`value`, t1.`limit`, t1.`date` FROM `balance` AS t1 LEFT JOIN `account` AS t2 ON t1.`account` = t2.`id` WHERE t1.`type` = 1;');
      
    $stmt->execute();
      
    $results $stmt->fetchAll();
      
    $link->closeDB();

      
    $table '      <H1>Open Account Balances</H1>
        <TABLE>
          <TR><TH>Account (Comment)</TH><TH>Total Due / Limit</TH><TH>As of...</TH></TR>
    insert_rows($results) . '
        </TABLE>' 
    "\n";

      return 
    $table;


    Current build of the to-be row builder:
    PHP Code:
    function insert_rows($results) {

      
    $currency0 = new NumberFormatter('en_US'NumberFormatter::CURRENCY);
      
    $currency0->setAttribute(NumberFormatter::FRACTION_DIGITS0);

      
    $currency2 = new NumberFormatter('en_US'NumberFormatter::CURRENCY);
      
    $currency2->setAttribute(NumberFormatter::FRACTION_DIGITS2);

      
    // process a row
      
    $total 0;
      
    $format = function($row) use ($currency0$currency2, &$total) {
        
    $total += $row['value'];
        
    $row['comment'] = ($row['comment'] ? ' (' $row['comment'] . ')' '');
        
    $row['value'] = ($row['calue'] ? $currency2->formatCurrency($row['value'], 'USD') : '');
        
    $row['limit'] = ($row['limit'] ? '/' $currency0->formatCurrency($row['limit'], 'USD') : '');
        
    $row['date'] = date_create($row['date'])->format('m/d/Y');
      };

      
    // format for display
      
    $display = array(
        
    // header => function($row) { return displayable value; }
        
    'Account (Comment)' => function($row) {
          return 
    $row['name'] . $row['comment'];
        },
        
    'Total Due / Limit' => function($row) {
          return 
    $row['value'] . $row['limit'];
        },
        
    'As of...' => function($row) {
          return 
    $row['date'];
        }
      );

      
    $rows NULL;
      foreach(
    $results as $result) {
        
    $rows .= '<TR>';
        foreach(
    $display as $header => $formatter) {
          
    $rows .= '<TD>' $formatter($result) . '</TD>';
        }
        
    $rows .= '</TR>' "\n";
      }

      return 
    $rows;


    One thing I will still need to figure out for the row builder is the fact its intent is to be a universal item, so maybe my result set will just need to be built/SELECT'ed in the same order as the displayed columns. Still need it to know how to learn or be told how to format what columns.

    Thanks for all the help!

    Edit: As I look this over, let me know if my idea for the "universal" action is right. No matter what page I am on, the "process a row" and "format for display" functions will always run a check for what was submitted, so all indexes will always be set, but simply be blank if not provided? So, I would need to submit the result set as well as a defined list of columns submitted/returned?

    Edit2: I got the $format to process by adding the following just after its definition. Let me know if this isn't correct.
    PHP Code:
    $results array_map($format$results); 
    Thanks again all. This is turning 40-80 line functions into something as short as 10-15 lines.
    Last edited by Triple_Nothing; January 5th, 2018 at 02:30 PM.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  22. #12
  23. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    Sorry to drag on, but just figured since I did a bit of re-writing, maybe an update to the followers was due...

    A new class to fetch any/all data:
    PHP Code:
    class DBFetch {

      private 
    $db;
      private 
    $link;
      private 
    $results;

      function 
    __construct() {
        
    $this->link = new Connection();
        
    $this->db $this->link->openDB();
      }

      public function 
    account() {
        
    $stmt $this->db->prepare('SELECT `id`, `name`, `active` FROM `account` ORDER BY `name` ASC;');
        
    $stmt->execute();
        
    $this->results $stmt->fetchAll();
        return [
    'title' => 'Account Management''headers' => ['Status''Account Name'], 'results' => $this->results];
      }

      public function 
    balance($year) {
        
    $stmt $this->db->prepare('SELECT t2.`name`, t1.`comment`, t1.`value`, t1.`date` FROM `balance` AS t1 LEFT JOIN `account` AS t2 ON t1.`account` = t2.`id` WHERE t1.`type` = 2 AND YEAR(t1.`date`) = ?;');
        
    $stmt->execute(array($year));
        
    $this->results $stmt->fetchAll();
        return [
    'title' => 'Open Account Balances''headers' => ['Account (Comment)''Total Due / Limit''As Of...'], 'results' => $this->results];
      }

      public function 
    invoice($year) {
        
    $stmt $this->db->prepare('SELECT t1.`value`, t2.`name`, t1.`id`, t1.`date`, t1.`adj_value`, t1.`comment`, t1.`paid` FROM `invoice` AS t1 LEFT JOIN `account` AS t2 ON t1.`account` = t2.`id` WHERE YEAR(t1.`date`) = ? ORDER BY MONTH(t1.`date`) DESC, t1.`date` ASC;');
        
    $stmt->execute(array($year));
        
    $this->results $stmt->fetchAll();
        return [
    'title' => 'Invoices''headers' => ['Paid''Due Date''Amount''Description''Adj. Amount''Comments'], 'results' => $this->results];
      }

      public function 
    paid_off($year) {
        
    $stmt $this->db->prepare('SELECT t2.`name`, t1.`comment`, t1.`value`, t1.`date` FROM `balance` AS t1 LEFT JOIN `account` AS t2 ON t1.`account` = t2.`id` WHERE t1.`type` = 2 AND YEAR(t1.`date`) = ?;');
        
    $stmt->execute(array($year));
        
    $this->results $stmt->fetchAll();
        return [
    'title' => 'Paid Off/Closed Accounts''headers' => ['Item''Amount''As Of...'], 'results' => $this->results];
      }


    The start to my universal function: (Just have to auto-define the requested item)
    PHP Code:
    function build_testing($year 2017) {

      
    // Example to make the fetch for and build the Invoices page/table
      
    $DBFetch = new DBFetch();
      
    $values $DBFetch->invoice($year);
      
    $table '      <H1>' $values['title'] . '</H1>
        <TABLE>
    insert_headers($values['headers']) . '
    insert_rows($values['results']) . '
        </TABLE>' 
    "\n";

      return 
    $table;


    The build for the Headers row:
    PHP Code:
    function insert_headers($arr) {
      
    $return '        <TR>';
      foreach(
    $arr as $var) {
        
    $return .= '<TH>' $var '</TH>';
      }
      
    $return .= '</TR>';
      return 
    $return;

    The build for the rows:
    PHP Code:
    function insert_rows($results) {

      
    $currency0 = new NumberFormatter('en_US'NumberFormatter::CURRENCY);
      
    $currency0->setAttribute(NumberFormatter::FRACTION_DIGITS0);

      
    $currency2 = new NumberFormatter('en_US'NumberFormatter::CURRENCY);
      
    $currency2->setAttribute(NumberFormatter::FRACTION_DIGITS2);

      
    // process a row
      
    $total 0;
      
    $format = function($row) use ($currency0$currency2, &$total) {
        
    $total += (isset($row['value']) ? $row['value'] : 0);
        
    $row['active'] = (isset($row['active']) ? ($row['active'] == 'Active' 'Inactive') : '');
        
    $row['comment'] = (isset($row['comment']) ? ' (' $row['comment'] . ')' '');
        
    $row['value'] = (isset($row['value']) ? $currency2->formatCurrency($row['value'], 'USD') : '');
        
    $row['limit'] = (isset($row['limit']) ? '/' $currency0->formatCurrency($row['limit'], 'USD') : '');
        
    $row['date'] = (isset($row['date']) ? date_create($row['date'])->format('m/d/Y') : '');
        return 
    $row;
      };

      
    $results array_map($format$results);

      
    // format for display
      
    $display = array(
        
    // header => function($row) { return displayable value; }
        
    'Active' => function($row) {
          return 
    $row['active'];
        },
        
    'Account (Comment)' => function($row) {
          return 
    $row['name'] . $row['comment'];
        },
        
    'Total Due / Limit' => function($row) {
          return 
    $row['value'] . $row['limit'];
        },
        
    'As of...' => function($row) {
          return 
    $row['date'];
        }
      );

      
    $rows NULL;
      foreach(
    $results as $result) {
        
    $rows .= '<TR>';
        foreach(
    $display as $header => $formatter) {
          
    $rows .= '<TD>' $formatter($result) . '</TD>';
        }
        
    $rows .= '</TR>' "\n";
      }

      return 
    $rows;


    Still need to figure out how to get the tables to build the correct columns based on which page/table is to be build.
    I defined isset() on all variables so far, so even on pages in which they don't exist, they will just be blank. I'm thinking this may be a bad option if using a loop to create my outcome, tho...

    Edit: Altered the items so instead of being set blank if not existing, they will hold a value of RemoveThisElement. I then loop over that array, unset()'ing all those items. This should leave any values who were originally set, and just holding a blank value.
    PHP Code:
    $format = function($row) use ($currency0$currency2, &$total) {
      
    $total += (isset($row['value']) ? $row['value'] : 0);
      
    $row['active'] = (isset($row['active']) ? ($row['active'] == 'Active' 'Inactive') : 'RemoveThisElement');
      
    $row['comment'] = (isset($row['comment']) ? ' (' $row['comment'] . ')' 'RemoveThisElement');
      
    $row['value'] = (isset($row['value']) ? $currency2->formatCurrency($row['value'], 'USD') : 'RemoveThisElement');
      
    $row['limit'] = (isset($row['limit']) ? '/' $currency0->formatCurrency($row['limit'], 'USD') : 'RemoveThisElement');
      
    $row['date'] = (isset($row['date']) ? date_create($row['date'])->format('m/d/Y') : 'RemoveThisElement');
      return 
    $row;
    };

    $results array_map($format$results);

    foreach(
    array_keys($results'RemoveThisElement') as $key) {
      unset(
    $array[$key]);

    Last edited by Triple_Nothing; January 6th, 2018 at 07:39 AM.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.

IMN logo majestic logo threadwatch logo seochat tools logo