PHP/mySQL-在"LIKE"子句中使用"CONCAT"和"AS"的结果 [英] PHP/mySQL - using result from 'CONCAT' and 'AS' in 'LIKE' clause
本文介绍了PHP/mySQL-在"LIKE"子句中使用"CONCAT"和"AS"的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码;
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();
}
}
问题是我想在where子句中使用temp col'STRING',但返回'unknown coloumn STRING
有人可以向我指出正确的方向吗,Phil
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
我已打印出查询;
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%'
推荐答案
将STRING换成`而不是'
Wrap STRING in ` instead of '
应该是:
..AS `STRING`
然后您在任何指向STRING的地方都应该是`STRING`
And then anywhere you refer to STRING should be `STRING`
这里应该可以解决此问题:
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 . " ) ;
这篇关于PHP/mySQL-在"LIKE"子句中使用"CONCAT"和"AS"的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文