Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 872189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:44:49+00:00 2026-05-15T10:44:49+00:00

I’m trying to do a group by using Zend framework. Here’s my code: $table

  • 0

I’m trying to do a group by using Zend framework. Here’s my code:

$table = new TableClass();
$select = $table->select();
$select->from ("table", array("date", "column1" => "sum(column1)"));
$select->group ( array ("date") );
$results = $table->fetchAll ($select);
$result = $results[0];
$date = $result->date;
$column1 = $result->column1;

TableClass extends ‘Zend_Db_Table_Abstract’.

I can see the query by looking at the mysql query log. The query is well formed – column1 is named in the query and the results look correct if I run the query in mysql workbench.

I cannot access the data in ‘column1’ – I always get this exception:

Uncaught exception ‘Zend_Db_Table_Row_Exception’ with message ‘Specified column “column1” is not in the row’

I can however access the date column without issue.

I tried:

  • accessing the columns by array index:
    $result[0]
    but you get an exception (can’t access the columns by index).

  • not using a column alias:
    $select->from (“table”, array(“date”, “sum(column1)”));
    $column1 = $result[“sum(column1)”];
    but you get an exception (no such column “sum(column1)”).

  • throwing in a Zend_Db_Expr:
    “column1” => new Zend_Db_Expr ( “sum(column1)” )
    but this doesn’t help.

Some other examples I have seen suggest the use of the column names without aggregate functions, ie. “column1” instead of “sum(column1)” but that doesn’t seem to me to be the answer – the query doesn’t have any aggregate functions in it so mysql won’t know what to do with it.

Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:44:50+00:00Added an answer on May 15, 2026 at 10:44 am

    Firstly, a quick tip for working with Zend_Db_Select (and by extension Zend_Db_Table_Select), you can view the generated SQL by invoking the toString method. It is vital to verify that your code generates the correct query before working with a result set:

    $select = $table->select();
    $select->from ("table", array("date", "column1" => "sum(column1)"));
    $select->group ( array ("date") );
    
    $sql = (string) $select; //Retrieve SQL as a string
    

    Or simply

    die($select); //print SQL
    

    I wrote the following test script using your example and have no problems:

    class Table extends Zend_Db_Table_Abstract 
    {
        protected $_primary = 'id';
        protected $_name = 'table';
    }
    
    $db = Zend_Db::factory('Pdo_Mysql', array(
        'dbname' => 'test',
        'username' => 'root',
        'password' => '',
        'host' => 'localhost'
    ));
    
    $table = new Table($db);
    
    $select = $table->select();
    $select->from ($table, array("date", "column1" => new Zend_Db_Expr("sum(column1)")));
    $select->group ( array ("date") );
    $sql = (string) $select;
    
    echo $sql;
    
    $results = $table->fetchAll ($select);
    $result = $results[0];
    $date = $result->date;
    $column1 = $result->column1;
    
    echo '<br>' . $date . ': ' . $column1;
    

    Use Zend_Debug::dump($result); to inspect data inside the Zend_Db_Table_Row if necessary.

    In my case the SQL generated is as follows:

    SELECT `table`.`date`, sum(column1) AS `column1` FROM `table` GROUP BY `date`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to select an H1 element which is the second-child in its group
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.