Jump to content

PHP SQL query


jaykappy

Recommended Posts

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']));
Link to comment
https://forums.phpfreaks.com/topic/279047-php-sql-query/
Share on other sites

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']));
Link to comment
https://forums.phpfreaks.com/topic/279047-php-sql-query/#findComment-1435427
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.