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

  • Home
  • SEARCH
  • 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 8342927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:54:26+00:00 2026-06-09T05:54:26+00:00

I have the following query that selects some records from the database: $select_person =

  • 0

I have the following query that selects some records from the database:

$select_person = $this->select()
        ->setIntegrityCheck(false)
        ->from(array('a' => 'tableA'), 
                array(new Zend_Db_Expr('SQL_CALC_FOUND_ROWS a.id'),
                        'a.cid',  
                        'a.email',
                        'final' => new Zend_Db_Expr( "concat( '<div 
                            style=\"color:#1569C7; font-weight:bold\">',
                            a.head , ' ' ,  a.tail,  '</div>')" ),
                        'a.red_flag'
                )
        )   
        ->joinLeft(array('b' => 'tableb'), ... blah blah)
        ->where('blah blah')
        ->order('a.head ASC')

I want to modify the above query so that it selects a different value for 'final' depending on the value of

a.red_flag.

which can have values – true or false.

I understand I can use the CASE statement of mysql – eg something like the following:

'final' => new Zend_Db_Expr("CASE a.red_flag WHEN 'true' THEN '$concatstr1'
                        ELSE '$concatstr2' END")

The value of $concatstr1 = "concat( '<div style=\"color:red; font-weight:bold\">', a.head , ' ' , a.tail, '</div>')" ;

The value of $concatstr2 = "concat( '<div style=\"color:blue; font-weight:bold\">', a.head , ' ' , a.tail, '</div>')" ;

However, it throws an error saying

Message: SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘div
style=”color:red; font-weight:bold”>’,
a.head , ‘ ‘ , ‘ at line 1

How can I make this query work?
Any help is greatly appreciated.

Thanks

  • 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-06-09T05:54:27+00:00Added an answer on June 9, 2026 at 5:54 am

    Finally, I found the error in my statement.
    The culprit was – I was using quotes in $concatstr1 and $concatstr2 inside the $select_person statement.
    The correct query should be formed as follows:

    $select_person = $this->select()
            ->setIntegrityCheck(false)
            ->from(array('a' => 'tableA'), 
                    array(new Zend_Db_Expr('SQL_CALC_FOUND_ROWS a.id'),
                            'a.cid',  
                            'a.email',
                            final' => new Zend_Db_Expr("CASE a.red_flag WHEN 'true' THEN $concatstr1 ELSE $concatstr2 END"),
                            'a.red_flag'
                    )
            )   
            ->joinLeft(array('b' => 'tableb'), ... blah blah)
            ->where('blah blah')
            ->order('a.head ASC');
    

    This is now returning me the appropriate value of ‘final‘ – concatstr1 when red_flag is true otherwise it is returning me concatstr2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
I have the following query that retrieve the number of users per country; SELECT
Dear all, I have a select query that currently produces the following results: DoctorName
I have two tables that I am joining with the following query... select *
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have the following query that runs in my Oracle database and I want
Suppose that I have a database query which looks like below - select name,
The following query is pretty simple. It selects the last 20 records from a
I have the following linq select query that loops round all the 'Places' linked
I have the following query that joins a bunch of tables. I'd like to

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.