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 8546583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:03:53+00:00 2026-06-11T13:03:53+00:00

I have this code: mysql_query( SELECT id as tc_id, firstname, surname, position, @concat :=

  • 0

I have this code:

mysql_query("
   SELECT id as tc_id, firstname, surname, position, @concat := CONCAT(firstname,' ',surname) 
   FROM tc 
   WHERE (@concat LIKE '%". mysql_real_escape_string($_REQUEST['search_term']) ."%');");

search_term just refers to the value of a text input.

When I run the SELECT statement in sequel pro locally – my mysql program – it works perfectly, selecting the appropriate rows. When I run the query however locally through my PHP page, it returns no rows, even though it should. Help anyone?

  • 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-11T13:03:54+00:00Added an answer on June 11, 2026 at 1:03 pm

    WHERE does not work on calculated columns, therefore your query, per se, will not work.

    It probably works because you locally have a @concat variable declared. It will also appear to work if you run the query twice in specific conditions, because your query might actually assign a @concat variable.

    What you want is

    SELECT id as tc_id, firstname, surname, position,
        CONCAT(firstname,' ',surname)  AS concat
    FROM tc HAVING concat LIKE '%<YOUR SEARCH TERM>%';
    

    As test:

    -- Declare a minimum table to match the query
    CREATE TABLE tc (id integer, firstname varchar(20), surname varchar(20), position integer);
    
    INSERT INTO tc (firstname, surname) VALUES ('alfa', 'bravo');
    
    -- Your query...
    
    SELECT id as tc_id, firstname, surname, position,
        @concat := CONCAT(firstname,' ',surname) FROM tc WHERE (@concat LIKE '%alfa%');
    
    -- ...returns nothing
    
    Empty set (0.00 sec)
    
    -- The proper query works.
    
    SELECT id as tc_id, firstname, surname, position, CONCAT(firstname,' ',surname)  AS concat FROM tc HAVING concat LIKE '%alfa%';
    +-------+-----------+---------+----------+------------+
    | tc_id | firstname | surname | position | concat     |
    +-------+-----------+---------+----------+------------+
    |  NULL | alfa      | bravo   |     NULL | alfa bravo |
    +-------+-----------+---------+----------+------------+
    1 row in set (0.00 sec)
    
    -- But if I declare a @concat variable    
    
    SELECT @concat := 'alfa';
    +-------------------+
    | @concat := 'alfa' |
    +-------------------+
    | alfa              |
    +-------------------+
    1 row in set (0.00 sec)
    
    -- Then your query SEEMS to work.
    
    mysql> SELECT id as tc_id, firstname, surname, position, @concat := CONCAT(firstname,' ',surname)  FROM tc  WHERE (@concat LIKE '%alfa%');
    +-------+-----------+---------+----------+------------------------------------------+
    | tc_id | firstname | surname | position | @concat := CONCAT(firstname,' ',surname) |
    +-------+-----------+---------+----------+------------------------------------------+
    |  NULL | alfa      | bravo   |     NULL | alfa bravo                               |
    +-------+-----------+---------+----------+------------------------------------------+
    1 row in set (0.00 sec)
    
    -- "SEEMS" because the select query isn't actually working:
    
    UPDATE tc SET firstname = 'delta';
    Query OK, 1 row affected (0.28 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    -- Having renamed the only row to "delta", a search for "alpha" should fail,
    -- but since @concat still holds 'alpha', then the query matches ALL rows:
    
    mysql> SELECT id as tc_id, firstname, surname, position, @concat := CONCAT(firstname,'    ',surname)  FROM tc  WHERE (@concat LIKE '%alfa%');
    +-------+-----------+---------+----------+------------------------------------------+
    | tc_id | firstname | surname | position | @concat := CONCAT(firstname,' ',surname) |
    +-------+-----------+---------+----------+------------------------------------------+
    |  NULL | delta     | bravo   |     NULL | delta bravo                              |
    +-------+-----------+---------+----------+------------------------------------------+
    1 row in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, $sqlstr = mysql_query( SELECT * FROM sales where passport =
I have this code: if ($firearm != ) { $sql_result5 = mysql_query(SELECT icon FROM
I have this PHP code: $result = mysql_query(SELECT banner FROM banners ) or die(mysql_error());
I have this PHP code: $result = mysql_query(SELECT distinct om_quote_no from `porders` order by
i have this code: <? $sql = mysql_query(SELECT * FROM VIDEOS ORDER BY ID
I have this simple PHP code: $query = mysql_query(SELECT `title`, `url_title` FROM `fastsearch` WHERE
I have this code: <?php include(db.php); $result = mysql_query(SELECT * FROM email); while($row =
I have this code: $result = mysql_query(SELECT * FROM quote ORDER BY RAND() LIMIT
i have this php code: $query = mysql_query(SELECT * FROM table WHERE id=$id); while($item
Hey there, why does this code not work? $qry = mysql_query(SELECT performerid,pic0 FROM .$table.

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.