-Original Message-
From: Dan Shirah [mailto:[EMAIL PROTECTED]
Sent: Friday, January 19, 2007 3:10 PM
To: php-general@lists.php.net
Subject: [PHP] Conditional Select
I have a page that shows all outstanding tickets, what I'm
trying to have it do is let users search by several
categories. I want to be able to filter the results based on
the user input.
For instance, say I have an employee that wants to find
ticket #2. He enters 2 in the Request ID field and also
enters 01/01/06 in the Date Requested field. How would I
return the ticket that matches both Request ID and Date
Requested fields? I have been able to return a result with
only 1 search criteria entered, but get no results with more than 1.
Below is the code I am working on.
else {
/* if the submit variable exists, the form has been
submitted - look for and process form data */
// display result
$request_id = $_POST['request_id'];
$date_entered = $_POST['date_entered']; $status =
$_POST['status']; $request_type = $_POST['request_type'];
?
form name=submitForm action=?php echo $_SERVER['PHP_SELF']; ?
method=post
table align=center width=780 cellpadding=2 cellspacing=2
border=0
tr
td width=185 align=rightspan
class=smallboldRequest Id:/span/td
td width=128 class=tblcellinput type=Text
value=?php echo $_POST['request_id']; ? name=request_id
size=8 maxlength=/td
td width=187 align=rightspan class=smallboldDate
Entered:/span/td
td width=254 class=tblcellinput type=Text
value=?php echo $_POST['date_entered']; ?
name=date_entered size=15 maxlength=/td
/tr
tr
td width=185 height=27 align=rightspan
class=smallboldStatus:/span/td
td width=128 class=tblcellinput type=Text
value=?php echo $_POST['status']; ? name=status
size=8 maxlength=/td
td width=187 align=rightspan
class=smallboldRequest Type:/span/td
td width=254 class=tblcellinput type=Text
value=?php echo $_POST['request_type']; ?
name=request_type size=15 maxlength=/td
/tr
/table
FORM ACTION=a href=javascript:clearForm() METHOD=POST
name=logoutform
table align=center border=0 cellpadding=0 cellspacing=0
width=780
tr
td colspan=2
input type=submit name=submit value=Searchnbsp;
input type=submit name=reset value=Reset
/td
/tr
/table
table align=center border=0 cellpadding=0 cellspacing=0
width=780
trtdnbsp;/td/tr
tr
td height=13 align=center class=tblheaddiv
align=centerstrongProcess
Payments /strong/div/td
/tr
tr
td colspan=6hr color=#006600 //td /tr
/table table align=center border=0 cellpadding=0
cellspacing=0
width=780
tr
td width=88 height=13 align=center
class=tblheaddiv align=centerRequest
ID /div/td
td width=224 height=13 align=center
class=tblheaddiv align=centerDate/Time
Entered /div/td
td width=156 height=13 align=center
class=tblheaddiv align=centerStatus/div/td td
width=156 height=13 align=center class=tblheaddiv
align=centerRequest Type /div/td td width=156
height=13 align=center class=tblheaddiv
align=centerLast Processed By/div/td /tr /table
?php $database = database; $host = host; $user =
username; $pass = password;
// Connect to the datbase
$connection = mssql_connect($host, $user, $pass) or die
('server connection failed');
$database = mssql_select_db($database, $connection) or
die ('DB selection failed');
// Query the table and load all of the records into an array.
**Note my SQL statement below, can I break in and out of PHP
like this to verify if multiple variables are set?*
*
$sql = SELECT
child_support_payment_request.credit_card_id,
credit_card_payment_request.credit_card_id,
date_request_received
FROM child_support_payment_request,
credit_card_payment_request
WHERE child_support_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id ? ?php if
($request_id !== '') {
AND credit_card_payment_request.credit_card_id = $request_id
}
?
?php if ($dateTime !== '') {
AND date_request_received = $dateTime;
}
?
?php
$result = mssql_query($sql) or die(mssql_error());
echo table width='780' border='1' align='center' cellpadding='2'
cellspacing='2' bordercolor='#00';
while ($row = mssql_fetch_array($result)) {
$id = $row['credit_card_id'];
$dateTime = $row['date_request_received']; echo tr;
echo td width='88' height='13' align='center'
class='tblcell'div align='center'$id/div/td; echo
td width='224' height='13' align='center'
class='tblcell'div align='center'$dateTime/div/td;
echo td width='156' height='13' align='center'
class='tblcell'div align='center'Open/div/td; echo
td width='156' height='13' align='center'
class='tblcell'div align='center'Payment Type/div/td;
echo td width='156' height='13' align='center'
class='tblcell'div align='center'Last Processed
By/div/td; echo /tr; } echo