Page 1 of 1

Trouble with IF

Posted: Mon Apr 25, 2011 1:32 pm
by thumbliner
Hello everyone,

I am new to this forum and PHP world. Doing my first project, a pretty complicated one to start with. I will be needing your help a lot to accomplish it.
Here is the first one.

1. I have a certain field called 'country'
2. I have small flag icons for every country.

WHAT DO I WANT TO DO?

Example - If the country is U.S.A., the U.S. flag shows up and is a link to www.domain.com/usa
If the country is Germany, the German flags shows up and is a link to www.domain.com/germany
If the country is not set, no flag shows up. END.

How do I execute this?

This is what I am doing to get the image
<img src="images/flags/<?php echo $row_rsPilots['country']; ?>.gif" alt="" name="Flag" width="20" height="20" id="Flag" />

How do make it a link to www.domain.com/'country'

Thanks in advance

Re: Trouble with IF

Posted: Mon Apr 25, 2011 1:39 pm
by strafingmoose
This is more of an HTML question than anything.

http://www.tizag.com/htmlT/htmlimagelinks.php

Re: Trouble with IF

Posted: Mon Apr 25, 2011 2:06 pm
by thumbliner
No Sir,

I am having trouble with the IF command of PHP.
As I said, I want to display all this only IF the country field is set.

I only got as close as

$image = "<img src=\"images/flags/{$row_rsPilots['country']}.gif\" alt=\"\" name=\"Flag\" width=\"20\" height=\"20\" />";
$link = "http://www.domain.com/{$row_rsPilots['country']}";
?>
<a href="<?php echo $link; ?>"><?php echo $image; ?></a>

Re: Trouble with IF

Posted: Mon Apr 25, 2011 2:14 pm
by CrowderSoup
How are you going to be figuring out what country the user is from in the first place?

Re: Trouble with IF

Posted: Mon Apr 25, 2011 2:16 pm
by thumbliner
He will fill a form.

See, the flags and fields are not the problem. That I can manage.

I just want to know the code which will do this

If field is set, show the image and make it a link to domain.com/country
If field is not set, no image, no link, nothing

Re: Trouble with IF

Posted: Mon Apr 25, 2011 2:51 pm
by strafingmoose
Your link should then be whatever value there was in the select combo for the country (ie: $link = "www.domain.com/".$_POST["country"])

If the $_POST["country"] is not set, then just don't show the link at all.

Your link should then be whatever value there was in the select combo for the country (ie: $link = "www.domain.com/".$_POST["country"])

If the $_POST["country"] is not set, then just don't show the link at all.

Code: Select all

if (isset($_POST["country"])) {
  $link = "www.domain.com/".$_POST["country"];
  $image = $rowPilots["country"];
  // just make an $html var that uses both elements above...
}
else
{
  $html = "";
}

echo $html;

Re: Trouble with IF

Posted: Mon Apr 25, 2011 2:57 pm
by califdon
thumbliner wrote:He will fill a form.

See, the flags and fields are not the problem. That I can manage.

I just want to know the code which will do this

If field is set, show the image and make it a link to domain.com/country
If field is not set, no image, no link, nothing
When do you want this to happen, as soon as the user fills in the country field, or when the whole form is processed by another script? In order to answer your question, that makes a sea-change of difference. If you want it to happen on the same web page the user is looking at, you can't possibly do that with PHP, since it has already finished running on the server; you'd have to do it with Javascript. If you want it to happen when the form is processed, we need to know where you want to display the flags--what web page or pages?