Jump to content

PHP SQL query


Go to solution Solved by Psycho,

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

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.