<?php
include 'connect.php';
$query = "SELECT * FROM (
SELECT CONCAT(customer_name, ' ', address, ' ', street, ' ', phone_1, ' ', phone_2, ' ', phone_3, ' ', phone_4) as `mysearch`
FROM customers) base
WHERE `mysearch` LIKE '%102%'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo "customer name: " . $row['customer_name'];
}
?>
查询正在运行,但我错过了能够回显结果的内容。它在phpmyadmin
中运行时返回结果。数据库中有2个条目应该返回
我的实际输出如下:
客户名称:客户名称:
表示它找到了2个条目,但我无法让它们回显。 customer_name
与数据库中的字段名称匹配。
答案 0 :(得分:2)
如果您希望在结果中包含customer_name
,则必须在子查询中将其选为分隔列:
SELECT
*
FROM (
SELECT
customer_name,
CONCAT(customer_name, ' ', address, ' ', street, ' ', phone_1, ' ', phone_2, ' ', phone_3, ' ', phone_4) as `mysearch`
FROM
customers
) base
WHERE
`mysearch` LIKE '%102%'