Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

directing if then statements...

Status
Not open for further replies.

klibby

Programmer
May 30, 2001
51
US
im writing a program that will look through a directory on a server, find all files in the directory with the extension .chr, open each one indivudually, then output a line on a table from each .chr file (flatfile database)......

I've added a search form on a script you get to before this one...... this script should read the inputs from the search and only display lines that match the filters.....

The way I am doing this is....


<<Code to open each .chr file>>
<<Code to split fields into variables>>

if ($input{'chkonline'} eq 'checked'){
if ($status1 eq 'Online'){
}

<<Code to Execute if $status1 = &quot;Online&quot; (Displays the line on the table>>
}
<<Close the file>>


The only important thing here is the if then statement, its the only thing giving me the problem.... what its doing is...... (take this for reference so I can explain... use the comments next to the lines to distinguish what part im talking about)

-----------
if ($input{'chkonline'} eq 'checked'){ # START IF 1
if ($status1 eq 'Online'){ # START IF 2
} # END IF 1

<<<CODE TO DISPLAY LINE>>>
} # END IF 2
----------


what thats susposed to do, is.... if in the previous form, leading to this script the checkbox &quot;chkonline&quot; is checked, then it should execute the next if statement (if ($status1 eq 'Online')) this should effect the <<CODE TO DISPLAY>>... this should be like saying, if the status is online then display the line... otherwise go to the next file.....


Now, what it is really doing is reading it like this...



-----------
if ($input{'chkonline'} eq 'checked'){ # START IF 1
if ($status1 eq 'Online'){ # START IF 2
} # END IF 2

<<<CODE TO DISPLAY LINE>>>
} # END IF 1
----------



(The end brackets are switched as to what if statement it belongs to) so basically, what this is doing, is, if the checkbox, chkonline is checked then go on... and if status is &quot;online&quot; then ____ (nothing... it ends here since its using the first end bracket belong to this statement)...

So instead of saying if the status is online show it.... its reading it as, if chkonline is checked then show it





Hope my explination makes sense.... i tried my best hehe... hard to explain that
 
oh yea.... if anybody has any other way of doing this, I'd love to hear it =)


heres what I need to do..... i have a form on another script leading to this... it has a bunch of fields that can be filtered... on this script, I need to display only records that pretain to selected filters
 
Whenever you nest commands or control structures you're brackets/parentheses will pair up in the following fashion:
Code:
{ { { { } } } }
4 3 2 1 1 2 3 4
So you'll want to keep that in mind. Now, the easiest way to do what you want is to combine both your conditions in one if statement using the short circuit AND operator (&&). This operator will test the first condition and if it's true continue to test the other condition, otherwise exit testing. So you're code becomes:
Code:
if ($input{'chkonline'} eq 'checked' && $status1 eq 'Online'){

brendanc@icehouse.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top