Can a grid, or report, be created from many tables?

A place for users and developers of the Xataface to discuss and receive support.

Postby walterbyrd » Thu Aug 30, 2007 3:18 pm

Can I pull together data from two, or more, tables, and display that data in a single grid? Or can I create a report using data from many tables?

I am looking for data from different tables to be displayed, all at once.
walterbyrd
 
Posts: 56
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Aug 30, 2007 4:06 pm

The best way to do this is with a custom action.

You can use the Dataface_RecordGrid class if you want to layout the results in a nice format.

e.g.

Code: Select all
// file actions/reports.php
class actions_reports {
function handle(){
   
      $sql = "select * from ...";
         
      
      $res = mysql_query($sql, df_db());
      if ( !$res ) trigger_error(mysql_error($app->db()));
      $data = array();
      while ( $row = mysql_fetch_assoc($res) ){
         $data[] = $row;
      }
      
      import('Dataface/SkinTool.php');
      import('Dataface/RecordGrid.php');
      $grid = new Dataface_RecordGrid($data);
      
        df_display(array('body'=>$grid->toHtml()), 'Dataface_Main_Template.html');
            
   }
}



Then you would access this action using index.php?-action=reports

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby walterbyrd » Thu Aug 30, 2007 4:47 pm

Thank you. I hope I'm not getting in over my head.
walterbyrd
 
Posts: 56
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Aug 30, 2007 10:31 pm

Definitely actions are getting right into the deep stuff.Ê With Dataface it is much easier when you can start thinking the dataface way.Ê If we are jumping directly into actions there is a good chance that we're approaching the problem the hard way.

I use custom actions with multiple table SQL queries usually just to print a special report of some kind.Ê The rest of the time we should be able to get by just navigating one table at a time - possibly with some calculated fields to add important information to each record.

If you need help - please post, and I'll do my best to steer you in the right direction.
-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby walterbyrd » Fri Aug 31, 2007 12:19 pm

I tried a simple test and, as you might expect, it didn't work for me. I'm sure I overlooked something simple.

These are the only two lines that I modified:

$sql = "select * from name";
$res = mysql_query($sql, df_db('hoadb'));

This is my error:

Fatal error: Class 'dataface_actions_reports' not found in /var/www/dataface/Dataface/Application.php on line 851

The location:

"/var/www/dataface/Dataface/Application.php"

is correct, that is where the file is located.
walterbyrd
 
Posts: 56
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Aug 31, 2007 2:58 pm

Have you read the tutorial pages on custom actions?Ê Please note the locations specified in there of where you should place your actions.

-Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby walterbyrd » Sat Sep 01, 2007 9:32 am

I read this:

https://framework.weblite.ca/documentation/tutorial/getting_started/dataface_actions

I then created a /var/www/hoadb/actions folder, and put reports.php in that folder. I deleted reports.php from the /var/www/dataface/actions directory.

This launches my application:

http://localhost/hoadb/

This gets me the following error:

http://localhost/hoadb/index.php?-action=reports

Fatal error: Class 'actions_reports' not found in /var/www/dataface/Dataface/Application.php on line 851

BTW: I set permission on the actions directory and the reports.php file to 777.

If I change "action" to "actions" like this:

http://localhost/hoadb/index.php?-actions=reports

I don't an error, but I don't get any results either.
walterbyrd
 
Posts: 56
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Sat Sep 01, 2007 10:00 am

Please post the content of your actions/reports.php file.
Probably you didn't place it inside a class.

e.g. the contents of this file should at least have:
class actions_reports {
function handle(&$params){
.... your stuff here ....
}
}



-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby walterbyrd » Sat Sep 01, 2007 10:24 am

The reports.php files is copied from your earilier post. I only changed these two lines:

$sql = "select * from name";
$res = mysql_query($sql, df_db('hoadb'));

The function handle(&$params) from your earlier post was function handle() I tried changing that, but it didn't make a difference.

The hello.php from the tutorial worked fine.

I tried deleting and rebuilding my application with ./makesite but I still get the same error with reports.

Here in the complete file:

db()));

$data = array();

while ( $row = mysql_fetch_assoc($res) ){

$data[] = $row;

}

import('Dataface/SkinTool.php');
import('Dataface/RecordGrid.php');

$grid = new Dataface_RecordGrid($data);

df_display(array('body'=>$grid->toHtml()), 'Dataface_Main_Template.html');

}

}
walterbyrd
 
Posts: 56
Joined: Wed Dec 31, 1969 5:00 pm

Postby walterbyrd » Sat Sep 01, 2007 10:32 am

Never mind. I got it. I was just missing a closing php bracket i.e. "?>". I am really sorry, I feel stupid.
walterbyrd
 
Posts: 56
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 30 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved