form output and ordering

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

Postby compudude86 » Tue Dec 12, 2006 10:34 am

ok, two questions here.... hopefully should be my last questions, but i want to implement something that would make a "printer friendly" version of the database, much like if you were to use "reports" in micro$oft access. and the second, i have about 10 columns in the database, and i want to organize the entire table alphabetically by the "description" column. i can do this by clicking "description" each time, but id like it to always be ordered that way.
compudude86
 
Posts: 59
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue Dec 12, 2006 12:13 pm

You can add the sort to your URL so that you can link directly to a page that is already sorted properly. You use the "-sort=colname" parameter in the url.

e.g.
http://yourdomain.com/yourapp/index.php?-table=foo&-action=list&-sort=description

or something like that.

Does that help.


If that isn't good enough, you can hard-code this into your index.php file:

if (!@$_GET['-sort'] and $_GET['-table'] == 'foo'){
$_GET['-sort'] = 'description';
$_REQUEST['-sort'] = 'description';
}

If you're looking to make a special report page that is nice for printing, you may want to just make a custom action though and lay it out exactly the way that you want.

Best regards

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

Postby compudude86 » Tue Dec 12, 2006 12:32 pm

thank you, that does indeed help. but how do i make a custom action to do this? basically i just want to strip it down, and have it in a basic table, so that each one will fit on an 8x11 sheet, landscape
compudude86
 
Posts: 59
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue Dec 12, 2006 1:59 pm

Start with the tutorial: http://framework.weblite.ca/documentation/tutorial/getting_started/dataface_actions

This just shows the basics, but should get you started..

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

Postby compudude86 » Wed Dec 13, 2006 9:35 am

You can add the sort to your URL so that you can link directly to a page that is already sorted properly. You use the "-sort=colname" parameter in the url.

>

e.g.

>http://yourdomain.com/yourapp/index.php?-table=foo&-action=list&-sort=description

>

or something like that.

>

Does that help.

>



>If that isn't good enough, you can hard-code this into your index.php file:



>if (!@$_GET['-sort'] and $_GET['-table'] == 'foo'){

$_GET['-sort'] = 'description';

> $_REQUEST['-sort'] = 'description';

}

>

If you're looking to make a special report page that is nice for printing, you may want to just make a custom action though and lay it out exactly the way that you want.

>

Best regards

>

Steve



ok, i tried the one on the url, and had to remove the -table=foo from the end for it to operate properly, but how would i form the hard code like this so that it would work?
compudude86
 
Posts: 59
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed Dec 13, 2006 1:11 pm

The -table=foo was an example. If your table was named bar it would be -table=bar. Basically, you can take any url from your app, and add -sort=description to have it sort by description. Or -sort=id to have it sort by id.
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby njw » Fri Dec 15, 2006 4:14 am

Another question Steve - is there a way to sort descending i.e. so I can show the latest items first by date?

Thanks

Neil
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Dec 15, 2006 2:48 pm

-sort=id+desc

Will sort the id field in descending order

-sort=id+desc,name+asc

Will sort lexicographically descending by id, and ascending by name.

Hope this helps

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

Postby njw » Fri Dec 15, 2006 4:46 pm

-sort=id+desc

>

Will sort the id field in descending order

>

-sort=id+desc,name+asc

>

Will sort lexicographically descending by id, and ascending by name.

>

Hope this helps

>

-Steve



Certainly does. Thanks

Neil
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Wed Jan 31, 2007 11:41 am

I followed the tutorial's example and modified it to match what I'm trying to do (which is create a printer friendly page)...When I execute my print action I get the following warnings:

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/bmmcom/public_html/dataface/Dataface/Record.php on line 1902

Warning: reset() [function.reset]: Passed variable is not an array or object in /home/bmmcom/public_html/dataface/Dataface/Record.php on line 1918

Warning: current() [function.current]: Passed variable is not an array or object in /home/bmmcom/public_html/dataface/Dataface/Record.php on line 1923


so far, my action code looks like:

function handle(&$params){

$app =& Dataface_Application::getInstance(); // reference to Dataface_Application object
$results =& $app->getResultSet(); // Current found set (Dataface_QueryTool object).

// Iterating through the results
$it =& $results->iterator();
while ($it->hasNext() ){
$record =& $it->next(); // $record is a Dataface_Record object
print_r($record->strvals());
unset($record); // necessary so that PHP doesn't just keep overwriting the same object.
}

df_display(array(), 'Printer_Friendly.html');
}


my basic idea is to add a button under the resultset from the original view, that button is a part of a form that uses my print action. The print action gets the current result set and prints it into a new template which I will format to look how I need it to.

Maybe my logic is far off...... but for now, I don't know where these errors are coming from.

Thanks in advance!
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Wed Jan 31, 2007 12:05 pm

I followed the tutorial's example and modified it to match what I'm trying to do (which is create a printer friendly page)...When I execute my print action I get the following warnings:

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/bmmcom/public_html/dataface/Dataface/Record.php on line 1902

Warning: reset() [function.reset]: Passed variable is not an array or object in /home/bmmcom/public_html/dataface/Dataface/Record.php on line 1918

Warning: current() [function.current]: Passed variable is not an array or object in /home/bmmcom/public_html/dataface/Dataface/Record.php on line 1923


so far, my action code looks like:

function handle(&$params){

$app =& Dataface_Application::getInstance(); // reference to Dataface_Application object
$results =& $app->getResultSet(); // Current found set (Dataface_QueryTool object).

// Iterating through the results
$it =& $results->iterator();
while ($it->hasNext() ){
$record =& $it->next(); // $record is a Dataface_Record object
print_r($record->strvals());
unset($record); // necessary so that PHP doesn't just keep overwriting the same object.
}

df_display(array(), 'Printer_Friendly.html');
}


my basic idea is to add a button under the resultset from the original view, that button is a part of a form that uses my print action. The print action gets the current result set and prints it into a new template which I will format to look how I need it to.

Maybe my logic is far off...... but for now, I don't know where these errors are coming from.

Thanks in advance!
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Wed Jan 31, 2007 12:06 pm

sorry, double post, had some wierd glitch where it didn't show my post.
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed Jan 31, 2007 12:07 pm

I apologize for the mistake in the example.

Before calling iterator() you need to call loadSet() on the $results object.

e.g.
$results->loadSet();
$it =& $results->iterator();
...

An alternative to this method is to obtain the user query using $app->getQuery(), and pass that to df_get_records_array() to return an array of Dataface_Record objects that you can loop through.

e.g.
$query =& $app->getQuery();
$records =& df_get_records_array($query['-table'], $query);
foreach ($records as $record){
// do something with the record


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

Postby generatedname » Wed Jan 31, 2007 1:14 pm

I'm sorry about soo many questions about what should be simple things. Ive searched and searched through the documentation, cannot find any way to loop through the fields of a given record.

Lets take your last response a step further:

$query =& $app->getQuery();
$records =& df_get_records_array($query['-table'], $query);
foreach ($records as $record){
}


now within the for loop, I'm trying to get another for loop to go through each field in the record to construct a table:


echo '';
foreach ($records as $record){
echo '';
-----------------This is where I want to start the for loop for each field in the record----------------
echo '';
-----------------Ending it here-------------------------------------------------------------------------
echo '';
//unset($record);
}
echo '
';
-----------------Print the Field data here--------------------------------------------------------------
echo '
';


I realize this is very sloppy but I just need something for now, then I can clean it up later =)

So far, if I put in the[ print_r($record->strvals()); ] without a loop for the fields, I can get all the record data in a "toString()" type of format, and the table creates as desired. But each record is in one cell and has more information than I want (obviously).

Thanks again for all your help, sorry again for being such a pain.
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Wed Jan 31, 2007 1:20 pm

Let me see if this shows up better, looks like some of my code got processed in my last post =/



echo '';
foreach ($records as $record){
echo '';
-----------------This is where I want to start the for loop for each field in the record----------------
echo '';
-----------------Ending it here-------------------------------------------------------------------------
echo '';
//unset($record);
}
echo '
';
-----------------Print the Field data here--------------------------------------------------------------
echo '
';
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Next

Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 12 guests

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