Group By - Adding an reading out datas

Discuss anything that's related to the Raxan framework

Group By - Adding an reading out datas

Postby anfuet » Wed Apr 25, 2012 8:02 am

Hello,
i work out the examples notepad and employees dir... all in all fine
I have a db with meetings, and all meetins are ordered by date

|date | meeting | person | status |
| 20.04.2012 | xxxx | xxx | xxx |
| | xxxx | xxx | xxx |
| 25.04.2012 | yyyyy | yyy | yyy |
| | yyyyy | yyy | yyy |
| | yyyyy | yyy | yyy |

Each entry should have a group ID... (I think it's useful)

How can I adding a new line to the meeting and how i can add a completly new meeting?
Can you help, please?

Regards
anfuet
 
Posts: 6
Joined: Tue Apr 24, 2012 1:40 pm

Re: Group By - Adding an reading out datas

Postby raymond » Thu Apr 26, 2012 12:43 am

Hi,

Welcome to the forum.

If you have modified the NotePad example you should be able to add a "new line" (or field?) to the data list. Just add an extra column in the table and add the fieldname (e.g {newfield}) to the view

To add a new meeting you will have to modify the save event by adding the fields from your meeting database.

Best regards,
__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Re: Group By - Adding an reading out datas

Postby anfuet » Thu Apr 26, 2012 7:40 am

Adding a new field works...
My problem (or maybe it it's not a problem) I have a field "group". And in my view I want to have that my data are showned in this group as structure

group 1
data 1
data 2
data 3
group 2
data 1
data 2
data 3

Is it possible to do a grup break with php/mysql.... But i don't know how does it works

I try this, but then... I am stuck
Code: Select all
            $sql="select * from massnahme";       
            $rows = $this->db->query($sql);
           
            $entries = array();
            while ($row = mysql_fetch_assoc($rows)){
                $entries[] = $row;
            }     
           
           
            $this->emplistBody->bind($rows,array(
                'altClass' => 'even',
                'selectClass' => 'rax-selected-pal rax-metalic',
                'key'=>'emp_no',
                'selected' => $this->data('emp-selected-ids'),
                'initRowCount' => $lower,
                'format' => array(
                    'abt'=>'capitalize',
                    'datum'=>'date:d M, Y',
                    'termin'=>'date:d M, Y',
                    'dat_erfull'=>'date:d M, Y'
                 )
            ));
           
            // add hover effect to table rows
            c('#emplist tbody tr')->hoverClass('hover');


And this is my problem. I do not know how...
anfuet
 
Posts: 6
Joined: Tue Apr 24, 2012 1:40 pm

Re: Group By - Adding an reading out datas

Postby raymond » Fri Apr 27, 2012 4:12 am

Hi,

You can use a callback to add a group header to your table. For example:

Code: Select all
function groupRows(&$row,$indx,  &$tpl) {
   if ($this->lastGroup!=$row['group']) {
      $this->lastGroup = $row['group'];
      $tpl = '<tr><td colspan="6" style="background:#ffe788;font-weight:bold">Group #'.$row['group'].'</td></tr>'.$tpl;
   }      
}


Here's a quick example using a modified version of your code:

table-group.zip
(11.87 KiB) Downloaded 251 times


Screenshot:
table-group.png
table-group.png (12.07 KiB) Viewed 32479 times



Have fun!
__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Re: Group By - Adding an reading out datas

Postby anfuet » Fri Apr 27, 2012 8:56 am

GREAT. It works :)
I have adepted it to my needs. Thanks.

Now I'm trying to put the same groupnumber for adding a new line in the same group.
Let's see if I succeed.

But one problem is left: my delete-function is the same like notepad, but I can onlye delete onnce, then not because my url get the ID og that one I want to delete...
anfuet
 
Posts: 6
Joined: Tue Apr 24, 2012 1:40 pm

Re: Group By - Adding an reading out datas

Postby anfuet » Wed May 02, 2012 8:00 am

anfuet wrote:Now I'm trying to put the same groupnumber for adding a new line in the same group.
Let's see if I succeed.


I have no success. I want to add a new line with the same group#. Besides the issue of the group I have an add button. The number will be automatically taken and inserted with the new datas.

Code: Select all
protected function newlineInGroup($e) {
            $id = $this->post->intVal('id');
            $sql="select group from person where id = ?";
           
            $group = $this->db->execQuery($sql, $id);
       
             
            $data = $this->post->filterValues('date,name,gender,'.$group);         
                       
            $rt = $this->db->tableInsert('person', $data);
           
            if(!$rt) $this->flashmsg($this->closeIcon.'Fehler beim Eintragen.', 'bounce', 'box notice');
            else $this->flashmsg($this->closeIcon.'Eintrag erfolgreich gespeichert.', 'bounce', 'rax-box success close click-cursor bmm');
           
            $this->redirectTo('index.php');     
             
        }
anfuet
 
Posts: 6
Joined: Tue Apr 24, 2012 1:40 pm

Re: Group By - Adding an reading out datas

Postby raymond » Wed May 09, 2012 12:39 am

Hi,

Sorry about the delay. I think you're retrieving the group id the wrong way. The execQuery() method returns an array or rows

Here's an update to your example posted above:
Code: Select all
    $id = $this->post->intVal('id');
    $sql="select group from person where id = ?";
   
    // get group id from database or default to id # 1
    $rows = $this->db->execQuery($sql, $id);
    $groupId =  isset($row[0]['group']) ? $row[0]['group'] : 1;

    // get data from post
    $data = $this->post->filterValues('date,name,gender');         
   
    // assign group id
    $data[group] = $groupId;
               
    $rt = $this->db->tableInsert('person', $data);


Best regards,
__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron