问题
so the query below will run in my phpmyadmin (with the variables as actual values as course), but when I run it in my php code I only get the first field returned (as if the second query after the UNION was never run).
$result=mysql_query("(SELECT RID, Name, Address, City, State, Zip_Code, Phone 
                      FROM restaurant 
                      WHERE Name = '$sql_name' AND City = '$sql_location') 
                      UNION 
                      (SELECT RID, Name, Address, City, State, Zip_Code, Phone 
                      FROM restaurant 
                      WHERE Name = '$sql_name' OR City = 'sql_location') ");
Can anyone help me as to why this is? Thanks for reading and I appreciate any and all help.
回答1:
City = 'sql_location')
        ^ missing '$' symbol
回答2:
Both of your union statements would return exactly the same records. UNion will filter out duplicates.
来源:https://stackoverflow.com/questions/12082009/union-working-in-phpmyadmin-but-not-in-my-php-code