(PHP) MySQL select query with array from $_GET

honeydipp

New Member
What I'm trying to do is go from a search URL such as this:\[code\]search.php?president=Roosevelt,+F.&congress=&nomination_received_by_senate=&state=CT\[/code\]To a MySQL query like this:\[code\]SELECT `name` FROM `nominations` WHERE president=`Roosevelt, F.` AND state=`CT`\[/code\]I have some code that strips any empty values from the URL, so I have an array as such:\[code\]Array ( [president] => Roosevelt, F. [state] => CT )\[/code\]Going from this to the SQL query is what is giving me trouble. I was hoping there might be some simple means (either by some variation of PHP's join() or http_build_query()) to build the query, but nothing seems to work how it needs to and I'm pretty lost for ideas even after searching.Not sure if it would require some messy loops, if there is a simple means, or if the way I'm going about trying to accomplish my goal is wrong, but I was hoping someone might be able to help out. Thanks in advance!Edit: To clarify, sometimes the inputs could be empty (as in the case here, congress and nomination_received_by_senate), and I'm hoping to accommodate this in the solution. And yes, I intend to implement means to avoid SQL injection. I have only laid out the basics of my plan hoping for some insight on my methods.
 
Back
Top