Reputation: 39
<?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'];
}
?>
The query is working, but I am missing something for being able to echo the results. It returns the results when ran in phpmyadmin
. There are 2 entries in the database that should be returned.
My actual output is as follows:
customer name: customer name:
indicating that it found the 2 entries, but I can't get them to echo. customer_name
is a match to a field name in the database.
Upvotes: 0
Views: 59
Reputation: 5316
If you want to have customer_name
in your result, you must select it as separated column in your subquery:
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%'
Upvotes: 2