View Full Version : How to set "IF" and "ELSE"
steffield
03-07-2002, 12:28 PM
I have managed to create a script which will extract information from my database and show it in a page, but I want to set up a couple of "IF"'s in it.
If you look at http://clients.thedesignroom.net/aogeastern/new/church_database.php you will see the page in question, I have also attached the file in .txt format, so you can see the code. You will also notice that links have been put in on church names and pastors names, when there is no URL or eMail available.
How do I tell the script to ignore to link if there is no entry in the url or email field?
Many Thanks
Ian Gunter
stone337
03-11-2002, 03:42 PM
if(empty($row[email]))
{
$email = '';
}
else
{
$email = "<a href=\"mailto:$row[email]\">$row[email]</a>";
}
The empty() function asks if $row[email] == ''. If it does then returns 1 or true. If not then returns 0 or false. You can inline the function with the if statment as shown above. Or you can evluate the result separately then as if($result). Or you can simply ask if($row[email] == ''). It's all the same. :)
Hope that helps.
-Kevin
Mr. Popularity
03-11-2002, 04:58 PM
Here's a script I wrote (minus the read parse) that does the same thing, hope it helps:
#!/usr/bin/perl
MAIN:
{
&ReadParse(*input);
&ProcessRequest;
}
sub ProcessRequest
{
# Defines the output as plain text
print "Content-type: text/plain\n\n";
# Opens the database
open(DATABASE, "<pm.dat");
my @member_lines = <DATABASE>;
close(DATABASE);
# Sets the variable "user" to null
my $user = "";
# Defines that the database is pipe delimited
for(@member_lines)
{
@split_line = split(/\|/, $_);
# Defines the variable "user" as the first column in the database
$user = @split_line[0];
# Converts the input name to lowercase
$input{'name'} =~ tr/A-Z/a-z/;
# Returns "true" if any name contains "monitor" or "moderator"
if ($input{'name'} =~ /monitor/ || $input{'name'} =~/moderator/)
{
print "true";
return;
}
# If the membername exists, returns "true" and denies user the right to use that name.
if ($input{'name'} eq $user) {
print "true";
return;
}
}
# If the membername is null, returns an error message saying so
if ((!exists($input{'name'})) || ($input{'name'} eq ""))
{
print "error\nInput name is null.";
return;
}
# Returns an error if the database cannot be opened.
unless (open(DATABASE, "pm.dat"))
{
print "error\nUnable to open the database.";
return;
}
# If the above conditions were not met, it assumes that the membername is not
# reserved and returns "false" which grants the member access to the Volano
# Chat server.
close(DATABASE);
print "false";
}
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.