Private Label and Cobranded VoIP Solutions
BrainCast internet & phone based message/memo recording & reminder organization system
Internet Phone Service and Broadband Phone Service by ViaTalk

Go Back   VoIP Forums, Internet Phone Service Forums, & Web Hosting Forums > CoderForums - Programming Discussion > General Programming Issues > Programming Languages & Technologies > PHP

Reply
 
Thread Tools Rating: Thread Rating: 237 votes, 4.99 average. Display Modes
  #1  
Old 03-07-2002, 12:28 PM
steffield's Avatar
steffield steffield is offline
Where's my ZX81 gone to?
 
Join Date: Dec 2000
Location: Harlow, Essex, UK and Ashland, OH, USA
Posts: 402
Send a message via AIM to steffield Send a message via Yahoo to steffield
How to set "IF" and "ELSE"

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/aog...h_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
Attached Files
File Type: txt church_database.txt (1.9 KB, 99 views)
Reply With Quote
  #2  
Old 03-11-2002, 03:42 PM
stone337 stone337 is offline
Registered User
 
Join Date: Feb 2002
Posts: 28
PHP Code:
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

Last edited by stone337; 03-11-2002 at 03:45 PM.
Reply With Quote
  #3  
Old 03-11-2002, 04:58 PM
Mr. Popularity's Avatar
Mr. Popularity Mr. Popularity is offline
Registered User
 
Join Date: Dec 2001
Posts: 609
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";
}
__________________
Chris
Apple Certified iPhone Developer
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump