Help with getting a dataset
Archived from the Xataface Users forum.
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 failsecho ‘<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.
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
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…
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.