OK i have a page which posts to three pages within it like this
http://localhost/EDI_Project/DisplayRes ... orders=yes
http://localhost/EDI_Project/DisplayRes ... nvoice=yes
http://localhost/EDI_Project/DisplayRes ... credit=yes
each one of these links has its own button and code
at the moment i have a basic select stored proc in SQL and it prints a table depending on what one of the above URL's is loaded.
i am now creating a filter for each on of these pages using a drop down
my question is would it be possible to add a where clause to the stored procedure but then if nothing is entered as a parameters it would just display all the records as before. this would really shorten my code if i can just have a where clause that when nothings entered it takes all rows.
thanks in advance
Negating a where clause
Moderator: General Moderators
Re: Negating a where clause
You could try something like this:
Code: Select all
$where = 1;
if (isset($_GET['where']))
{
$where = $_GET['where'];
}
$sql = "SELECT foo, bar FROM tablename WHERE {$where}";-
markyboy17
- Forum Newbie
- Posts: 7
- Joined: Mon Jan 16, 2012 3:38 am
Re: Negating a where clause
Thanks but that didn't work
i have solved the problem so if anyone is wondering you have to change the query in the stored proc to this
create proc SelectPracticeIf (@name char(50))
as
if (@name = '')
begin
select customer_id,name,sales_rep,credit_limit from customer
end
else
begin
select customer_id,name,sales_rep,credit_limit from customer WHERE name=@name
end
and then in the php i have this
i appreciate your help thought i would post this if anyone else was wondering
i have solved the problem so if anyone is wondering you have to change the query in the stored proc to this
create proc SelectPracticeIf (@name char(50))
as
if (@name = '')
begin
select customer_id,name,sales_rep,credit_limit from customer
end
else
begin
select customer_id,name,sales_rep,credit_limit from customer WHERE name=@name
end
and then in the php i have this
Code: Select all
$dropdown = $_POST['DropDownList'];
if(!(isset ($dropdown)))
{
$dropdown = '';
}
$sql = "SelectPracticeIf ?";
$params = array(&$dropdown);
$results = sqlsrv_query($conn,$sql,$params);