Trouble with IF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thumbliner
Forum Newbie
Posts: 6
Joined: Mon Apr 25, 2011 1:21 pm

Trouble with IF

Post 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
strafingmoose
Forum Newbie
Posts: 15
Joined: Mon Apr 18, 2011 2:56 pm

Re: Trouble with IF

Post by strafingmoose »

This is more of an HTML question than anything.

http://www.tizag.com/htmlT/htmlimagelinks.php
thumbliner
Forum Newbie
Posts: 6
Joined: Mon Apr 25, 2011 1:21 pm

Re: Trouble with IF

Post 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>
User avatar
CrowderSoup
Forum Newbie
Posts: 18
Joined: Thu Apr 21, 2011 2:56 pm
Location: Murray, UT

Re: Trouble with IF

Post by CrowderSoup »

How are you going to be figuring out what country the user is from in the first place?
thumbliner
Forum Newbie
Posts: 6
Joined: Mon Apr 25, 2011 1:21 pm

Re: Trouble with IF

Post 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
strafingmoose
Forum Newbie
Posts: 15
Joined: Mon Apr 18, 2011 2:56 pm

Re: Trouble with IF

Post 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;
Last edited by strafingmoose on Mon Apr 25, 2011 3:00 pm, edited 1 time in total.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Trouble with IF

Post 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?
Post Reply