agr8lemon
04-08-2010, 03:55 PM
Hello everyone.
I have a page with 3 separate drop down choices.
Search SHEC Departments
Search SJCF Departments
Search SHEC Employees
I'd like to show the results of the search on the same page. I'm trying to determine what SQL query to run based on what SELECT button they push.
I'm having a issue trying to use a switch with $_GET. Here is an example of what I have.
Sorry if the code is sloppy, I've been trying a bunch of things and have not organized it yet. :)
<?php
require"../includes/dept_mssql.php"; //Connect to the Department database
require"../includes/emp_mssql.php"; //Conect to the Employee database
//show all errors
error_reporting(E_ALL);
ini_set('display_errors', '3')
?>
<html>
<head>
</head>
<body>
<div align="center">
<h1> Hospital Phone Directory </h1>
<hr />
</div>
<div align=center>
<h2>
SHEC Department Search
</h2>
<form name=shec_depart action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<?php
$sql_depart_shec="SELECT Name, Depart_ID, Facility FROM dbo.Depart_tbl WHERE Facility = 'SHEC' OR Facility = 'BOTH' ORDER BY Name ASC";
$shecResult=odbc_exec($dept_conn, $sql_depart_shec);
$shecOptions="";
while($shecRows=odbc_fetch_array($shecResult)){
$shecId=$shecRows["Depart_ID"];
$shecDepartments=$shecRows['Name'];
$shecOptions.="<OPTION VAULE=\"$shecId\">".$shecDepartments;
}
?>
<select name="shec-depart">
<OPTION VALUE=>SHEC Departments<?php echo $shecOptions ?>
</SELECT>
<input type="submit" name="Submit" value="Search" />
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
</div>
<div align=center>
<h2>SJCF Department Search</h2>
<form name=sjcf_depart action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<?php
$sql_depart_sjcf="SELECT Name, Depart_ID, Facility FROM dbo.Depart_tbl WHERE Facility = 'SJCF' OR Facility = 'BOTH' ORDER BY Name ASC";
$sjcfResult=odbc_exec($dept_conn, $sql_depart_sjcf);
$sjcfOptions="";
while($sjcfRows=odbc_fetch_array($sjcfResult)){
$sjcfId=$sjcfRows["Depart_ID"];
$sjcfDepartments=$sjcfRows['Name'];
$sjcfOptions.="<OPTION VAULE=\"$sjcfId\">".$sjcfDepartments;
}
?>
<select name="sjcf-dept" STYLE="width: 275px">
<OPTION VALUE=>SJCF Departments<?php echo $sjcfOptions ?>
</SELECT>
<input type="submit" name="Submit" value="Search" />
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
</div>
<div align=center>
<h2> SHEC Employee Search</h2>
<form name=shec_emp action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<?php
$sql_emp_shec="SELECT * FROM dbo.Emp_tbl WHERE Facility = 'SHEC' OR Facility = 'BOTH' ORDER BY FirstName ASC";
$result=odbc_exec($emp_conn, $sql_emp_shec);
?>
<select name="shec-name" STYLE="width: 275px">
<OPTION VALUE=A>A</option>
<OPTION VALUE=B>B</option>
</SELECT>
<input type="submit" name="Submit" value="Search" />
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
<?php
if($_GET['submitted'] == true)
{
switch ($_SERVER['QUERY_STRING'])
{
case "shec-dept";
echo "do some query";
break;
case "sjcf-dept";
echo "Do another query";
break;
case "shec-name";
echo "Do yet a different query";
break;
defalut;
echo "error";
}
}
else
{
echo 'Get is not set';
}
odbc_close($dept_conn);
odbc_close($emp_conn);
?>
At them moment the page displays, however making a selection from the dropdowns and hitting the submit button does not display any of the switch echos.
Any help would be wonderful!! Thank you!
I have a page with 3 separate drop down choices.
Search SHEC Departments
Search SJCF Departments
Search SHEC Employees
I'd like to show the results of the search on the same page. I'm trying to determine what SQL query to run based on what SELECT button they push.
I'm having a issue trying to use a switch with $_GET. Here is an example of what I have.
Sorry if the code is sloppy, I've been trying a bunch of things and have not organized it yet. :)
<?php
require"../includes/dept_mssql.php"; //Connect to the Department database
require"../includes/emp_mssql.php"; //Conect to the Employee database
//show all errors
error_reporting(E_ALL);
ini_set('display_errors', '3')
?>
<html>
<head>
</head>
<body>
<div align="center">
<h1> Hospital Phone Directory </h1>
<hr />
</div>
<div align=center>
<h2>
SHEC Department Search
</h2>
<form name=shec_depart action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<?php
$sql_depart_shec="SELECT Name, Depart_ID, Facility FROM dbo.Depart_tbl WHERE Facility = 'SHEC' OR Facility = 'BOTH' ORDER BY Name ASC";
$shecResult=odbc_exec($dept_conn, $sql_depart_shec);
$shecOptions="";
while($shecRows=odbc_fetch_array($shecResult)){
$shecId=$shecRows["Depart_ID"];
$shecDepartments=$shecRows['Name'];
$shecOptions.="<OPTION VAULE=\"$shecId\">".$shecDepartments;
}
?>
<select name="shec-depart">
<OPTION VALUE=>SHEC Departments<?php echo $shecOptions ?>
</SELECT>
<input type="submit" name="Submit" value="Search" />
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
</div>
<div align=center>
<h2>SJCF Department Search</h2>
<form name=sjcf_depart action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<?php
$sql_depart_sjcf="SELECT Name, Depart_ID, Facility FROM dbo.Depart_tbl WHERE Facility = 'SJCF' OR Facility = 'BOTH' ORDER BY Name ASC";
$sjcfResult=odbc_exec($dept_conn, $sql_depart_sjcf);
$sjcfOptions="";
while($sjcfRows=odbc_fetch_array($sjcfResult)){
$sjcfId=$sjcfRows["Depart_ID"];
$sjcfDepartments=$sjcfRows['Name'];
$sjcfOptions.="<OPTION VAULE=\"$sjcfId\">".$sjcfDepartments;
}
?>
<select name="sjcf-dept" STYLE="width: 275px">
<OPTION VALUE=>SJCF Departments<?php echo $sjcfOptions ?>
</SELECT>
<input type="submit" name="Submit" value="Search" />
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
</div>
<div align=center>
<h2> SHEC Employee Search</h2>
<form name=shec_emp action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<?php
$sql_emp_shec="SELECT * FROM dbo.Emp_tbl WHERE Facility = 'SHEC' OR Facility = 'BOTH' ORDER BY FirstName ASC";
$result=odbc_exec($emp_conn, $sql_emp_shec);
?>
<select name="shec-name" STYLE="width: 275px">
<OPTION VALUE=A>A</option>
<OPTION VALUE=B>B</option>
</SELECT>
<input type="submit" name="Submit" value="Search" />
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
<?php
if($_GET['submitted'] == true)
{
switch ($_SERVER['QUERY_STRING'])
{
case "shec-dept";
echo "do some query";
break;
case "sjcf-dept";
echo "Do another query";
break;
case "shec-name";
echo "Do yet a different query";
break;
defalut;
echo "error";
}
}
else
{
echo 'Get is not set';
}
odbc_close($dept_conn);
odbc_close($emp_conn);
?>
At them moment the page displays, however making a selection from the dropdowns and hitting the submit button does not display any of the switch echos.
Any help would be wonderful!! Thank you!