jaykappy Posted June 11, 2013 Share Posted June 11, 2013 (edited) I am passing 2 parameters in my URL to a page. I want to query on both...IN THE example below I am only querying 1.... how do I change the syntax to query for both the Dept and the Yr 100.100.2.31:83/Pageindex.php?Dept=Engineering&Yr=1972 Thanks in advance for your help.... echo $_GET["Dept"]; echo $_GET["Yr"]; $query = " SELECT Id,Yr,ProjectName,Department,Owner,MaplibraryName, FROM tbl_library WHERE Department = :dept ORDER BY Yr DESC "; $stmt = $db->prepare($query); $stmt->execute(array(":dept" => $_GET['Dept'])); Edited June 11, 2013 by jaykappy Quote Link to comment https://forums.phpfreaks.com/topic/279047-php-sql-query/ Share on other sites More sharing options...
Solution Psycho Posted June 11, 2013 Solution Share Posted June 11, 2013 (edited) Depends. Do you want records that match the Department AND the year. Or, do you want records that match the Department OR the year? SELECT Id,Yr,ProjectName,Department,Owner,MaplibraryName, FROM tbl_library WHERE Department = :dept AND Yr = :year ORDER BY Yr DESC SELECT Id,Yr,ProjectName,Department,Owner,MaplibraryName, FROM tbl_library WHERE Department = :dept OR Yr = :year ORDER BY Yr DESC $stmt = $db->prepare($query); $stmt->execute(array(":dept" => $_GET['Dept'], ":year" => $_GET['Yr'])); Edited June 11, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/279047-php-sql-query/#findComment-1435427 Share on other sites More sharing options...
jaykappy Posted June 11, 2013 Author Share Posted June 11, 2013 FANTASTIC....I was close....I was missing the AND in the WHERE clause...oops... but had the $stmt correct in my testing.... THANKS FOR YOUR EYES AND HELP....VERY APPRECIATED... CHEERS. Quote Link to comment https://forums.phpfreaks.com/topic/279047-php-sql-query/#findComment-1435428 Share on other sites More sharing options...
jaykappy Posted June 11, 2013 Author Share Posted June 11, 2013 looking back at my $stmt ..... nope I had that incorrect as well.... THANKS AGAIN... Quote Link to comment https://forums.phpfreaks.com/topic/279047-php-sql-query/#findComment-1435429 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.