Forum Moderators: coopster
The drop down box contains s_item
=PartNumber value asphericallenses.partnumber
=Diameter1 value asphericallenses.diameter1 +/-5%
=Diameter2 value asphericallenses.diameter2 +/-5%
Text Box conatins s_word
$a_s_item = s_Item
$a_s_word = s_word
// Works fine by it's self with asphericallenses.partnumber
Where $a_s_item like '%$a_s_word%'
Results:
[localhost...]
// Works fine by it's self with asphericallenses.diameter1 or asphericallenses.diameter2 Searches 5% variance + or -
Where $a_s_item between ((($a_s_word * .05) - $a_s_word) * -1) and (($a_s_word * .05) + $a_s_word)
Results:
[localhost...]
I would like a evaluation statement to decide which routine to pass to the WHERE clause. can I use an IF function? or What do I use?
Am I correct? IF(Evaluate, True, False)
Where if($a_s_item='asphericallenses.partnumber', $a_s_item like '%$a_s_word%', $a_s_item between ((($a_s_word * .05) - $a_s_word) * -1) and (($a_s_word * .05) + $a_s_word))
SQL Routine MYSQL & PHP:
$w_sqlstr = "SELECT asphericallenses.PartNumber, asphericallenses.Diameter1, asphericallenses.Diameter2, asphericallenses.FocalLength, asphericallenses.SphericalRadius, asphericallenses.CenterThickness, asphericallenses.Material FROM asphericallenses WHERE (if($a_s_item='asphericallenses.partnumber', $a_s_item like '%$a_s_word%', $a_s_item between ((($a_s_word * .05) - $a_s_word) * -1) and (($a_s_word * .05) + $a_s_word)))";
You are correct about how the IF CONTROL FLOW functions, but I'm not sure you are getting the result set returned that you are expecting.
Currently, you are saying,
"select this fieldlist from this database WHERE..."
if (the drop-down-box item is equal to the item in the current row) {
return rows where the drop-down-box item is like the text-box word
} else {
return rows where the drop-down-box item is between
text-box word -5% variance
and
text-box word +5% variance
}
Else then I want the following to show up in the Where Clause
$a_s_item between ((($a_s_word * .05) - $a_s_word) * -1) and (($a_s_word * .05) + $a_s_word)
Thanks in advance
$where_clause = 'WHERE ';
if (isset($_POST['s_item'])) {
$where_clause = "$a_s_item like '%$a_s_word%'";
} else {
$where_clause = "$a_s_item between ((($a_s_word * .05) - $a_s_word) * -1)
and (($a_s_word * .05) + $a_s_word)";
}
$sql = "SELECT ... FROM ... $where_clause...";
Where to I put the routine
if (isset($s_item)) {
$where_clause = "\$a_s_item like '%\$a_s_word%'"; }
else { $where_clause = "\$a_s_item between ((($\a_s_word * .05) - \$a_s_word) * -1) and ((\$a_s_word * .05) + \$a_s_word)";
}echo $where_clause;
[edited by: jatar_k at 4:41 pm (utc) on Feb. 20, 2004]
[edit reason] too much code see PHP Charter [/edit]