Page 1 of 1

Help with getting a dataset

PostPosted: Wed Mar 28, 2012 2:07 pm
by wisni1rr
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.

Re: Help with getting a dataset

PostPosted: Thu Mar 29, 2012 9:58 am
by shannah
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

Re: Help with getting a dataset

PostPosted: Thu Mar 29, 2012 1:32 pm
by wisni1rr
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...

Re: Help with getting a dataset

PostPosted: Fri Mar 30, 2012 9:36 am
by shannah
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.