PHP/mySQL - using result from 'CONCAT' and 'AS' in 'LIKE' clause

Posted by Phil Jackson on Stack Overflow See other posts from Stack Overflow or by Phil Jackson
Published on 2010-04-20T05:40:39Z Indexed on 2010/04/20 5:43 UTC
Read the original article Hit count: 241

Filed under:
|
|
|
|

Hi I have the following code;

if( ! empty( $post['search-bar'] ) ) {
    $search_data = preg_replace("#\s\s#is", '', preg_replace("#[^\w\d\s+]#is", '', $post['search-bar'] ) );
    $data_array = explode( " ", $search_data );
    $data_array = "'%" . implode( "%' OR '%", $data_array ) . "%'"; 
    $query = "SELECT CONCAT( PROFILE_PROFFESION, FIRST_NAME, LAST_NAME, DISPLAY_NAME) AS 'STRING' FROM `" . ACCOUNT_TABLE . "` WHERE STRING LIKE ( " . $data_array . " ) AND BUSINESS_POST_CODE LIKE '" . substr(P_BUSINESS_POST_CODE, 0, 4) . "%'";

    $q = mysql_query( $query, $CON ) or die( "_error_" . mysql_error() );   
    if( mysql_num_rows( $q ) != 0 ) {
        die();
    }
}

Problem is I want to use the temp col 'STRING' in the where clause but is returning 'unknown coloumn STRING Can any one point me in the right direction, regards Phil

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql