Welcome to the nuBuilder forums!

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

Help or Hints requested..

Locked
ricklincs
Posts: 78
Joined: Mon Aug 01, 2011 5:39 pm

Help or Hints requested..

Unread post by ricklincs »

Hello All. I have a form called work that has fields/objects called arrival_date, working_date, completed_date, and departed_date.

I would like to add a status field/object (to be shown only on browse) that would show at what stage the work was at (ie Arrived/Working/Completed/Departed).. If the work had a value in arrival_date it would be Arrived, if it also had a value in working_date then the status would be Working and so on... Probably simple, but would be grateful for any pointers/hints.
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Help or Hints requested..

Unread post by massiws »

ricklincs,
if you don't want to store the stage of the work in a table field, you can built it creating a temp table in Custom Code > Before Browse (http://wiki.nubuilder.com/tiki-index.ph ... ore_Browse);
An example:

Code: Select all

$sql  = "CREATE TABLE #browseTable#";
$sql .= " SELECT * FROM table ... ";
nuRunQuery($sql);

/* Add a column to temp table */
nuRunQuery("ALTER TABLE #browseTable# ADD status VARCHAR(150) NOT NULL ");

$rs = nuRunQuery("SELECT * FROM #browseTable# ");

/* For each record, fill the new column with the right value */
while ($row = db_fetch_object($rs)) {
    $ID = $row->table_id;
    if ($row->completed_date) {
      $status = 'Completed';
    }
    else if ($row->departed_date) {
      $status = 'Departed';
    }
    else if () {
      // to be continued ...
    }
    
    /* Update temp table */
    $sql = "UPDATE #browseTable# SET status = '".$status."' WHERE table_id = '".$ID."'";
    nuRunQuery($sql);
}
Then add the new status field in browse tab.

Hope this helps,
Max
shane
Posts: 100
Joined: Mon Jun 15, 2009 10:04 am

Re: Help or Hints requested..

Unread post by shane »

what I would do is add another field for storing the status, and on the after save event in PHP I would update this field based on your criteria, then all you need to do is add that field to the browse, this keeps the sql in browser simple
ricklincs
Posts: 78
Joined: Mon Aug 01, 2011 5:39 pm

Re: Help or Hints requested..

Unread post by ricklincs »

Thanks guys. Big Help. :D
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Help or Hints requested..

Unread post by admin »

.
Locked