PHP / MySQL - 'CONCAT' den ve 'AS' sonucu kullanarak 'LIKE' maddesinde

3 Cevap php

Merhaba aşağıdaki kodu var;

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();
    }
}

Sorun ben nerede yan tümcesi geçici col 'STRING' kullanmak istiyorum ama bilinmeyen Kolon STRING herhangi biri bana doğru yönde işaret edebilir 'dönen, Phil ilgili

Ben sorgu dışarı basılmış;

SELECT PROFILE_PROFFESION, FIRST_NAME, LAST_NAME, DISPLAY_NAME 
FROM nnn_accounts 
WHERE 
  CONCAT( PROFILE_PROFFESION, FIRST_NAME, LAST_NAME, DISPLAY_NAME) 
  LIKE ( '%web%' OR '%design%' ) 
AND BUSINESS_POST_CODE LIKE 'NG19%'

3 Cevap

`Yerine 'in STRING Wrap

Should be: ..AS `STRING`

Ve sonra her yerde STRING bakmalıdır olmak `STRING`

Edit: Here this should solve it:

SELECT CONCAT( PROFILE_PROFFESION, FIRST_NAME, LAST_NAME, DISPLAY_NAME) AS `STRING`
FROM `" . ACCOUNT_TABLE . "` 
WHERE BUSINESS_POST_CODE LIKE '" . substr(P_BUSINESS_POST_CODE, 0, 4) . "%'"
HAVING `STRING` LIKE ( " . $data_array . " ) ;

Etrafında tırnak kaldırın 'STRING'

Daha uygun sözdizimi oldu

SELECT CONCAT( PROFILE_PROFFESION, FIRST_NAME, LAST_NAME, DISPLAY_NAME) AS `STRING` FROM `tablename` WHERE BUSINESS_POST_CODE LIKE 'NG19%' HAVING `STRING` LIKE '%web%' OR `STRING` LIKE '%design%'