UNION working in phpmyadmin, but not in my PHP code

微笑、不失礼 提交于 2020-01-17 15:09:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!