Help with getting a dataset

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

Help with getting a dataset

Postby wisni1rr » Wed Mar 28, 2012 2:07 pm

Code: Select all
  $app =& Dataface_Application::getInstance();
        $query =& $app->getQuery();
        $GENERAL = df_get_records_array('GENERAL', $query);
       
$SoldPrice = $GENERAL->val('SoldPrice'); --this line fails

echo '<td>'.min($SoldPrice).'</td>//


I'm trying to find away to save all the SoldPrice fields into an array. I want to call the array using the min($array) to calculate the minimum value of the array in the field.
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Help with getting a dataset

Postby shannah » Thu Mar 29, 2012 9:58 am

Not sure what you are trying to do exactly. If you're trying to obtain the min value of a column for a data set, then you can either do this with a custom SQL query, or you'll need to loop through each record in the found set and compare each value to find the minimum value. Your current code just displays the minimum of a single value - which is, of course, that value.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Help with getting a dataset

Postby wisni1rr » Thu Mar 29, 2012 1:32 pm

What I am doing is including a section on my list view to display some totals of the current query. I need to find various aggregate values (MIN, MAX, COUNT, AVG)

I'm not sure how to go about this...
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Help with getting a dataset

Postby shannah » Fri Mar 30, 2012 9:36 am

You could use the Dataface_QueryBuilder object to build the SQL query for the current query, but then just change the select clause to use mysql aggregate functions.

E.g.
Code: Select all
$app = Dataface_Application::getInstance();
$query = $app->getQuery();
$qb = new Dataface_QueryTool($query['-table'], $query);
$sql = "select max(col1), avg(col2), sum(col3) ".$qb->_from().$qb->_where();
$res = mysql_query($sql, df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()));
$results = mysql_fetch_row($res);
$max = $results[0];
$avg = $results[1];
$sum = $results[2];


Or something like this.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 6 guests

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