Click to See Complete Forum and Search --> : Problem with IF in a query


esm
05-25-2003, 05:24 AM
what is wrong with the following:

elseif($field=='show_detail'){
if($show_detail==1){
$query .= " and $field = $show_detail ";}
elseif($show_detail==0){
$query .= " and $field = $show_detail ";}
}


If I leave it in the query, the query returns no results.

If I remove it from the query, the query works properly but, of course, without including the show_detail.

The html looks like:
<tr class=tbl_light2>
<td>Show Detail</td>
<td>
<select name=show_detail>
<option value=2>---</option>
<option value=1>Yes</option>
<option value=0>No</option>
</select></td>
</tr>

How do I change it so that I can include the show_detail in the query???

Thanks

koeniepoenie
05-25-2003, 05:43 AM
you may try something like this:
$query .= " AND $field = '$show_detail'";

esm
05-25-2003, 05:57 AM
Thanks :) , but that didn't work. :(

Here is the code that immediately precedes the show_detail section

$query = "select * from idx_link where 0=0 ";
$i=0;
while($i<count($fields)) {
$field = $fields[$i];

global $$field;

if($field=='category_id' && !empty($cat))
$query .= "and $field = $cat ";
// mod for link_id
elseif($field=='link_id' && !empty($link_id))
$query .= "and $field = $link_id ";