Jump to content

Trouble with IF


thumbliner

Recommended Posts

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

Link to comment
Share on other sites

The link is the easy part, as long as you've sorted how to display the image. It looks like `country` holds the value you need, so just wrap the image in an <a href tag using that value. I've stored the values in variables to make the tag more concise.

 

$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>

Link to comment
Share on other sites

:-\

I am new to PHP but not new to common sense.  :P

That much I know.

 

I am having trouble with this sort of stuff

 

<?php If (isset($row_rsPilots['country']));

{ WHAT DO I WRITE HERE?

} ?>

 

The problem I am facing is that I have already opened a 'php' tag <?php

When I use that as an extension for the domain or image, the repetition is creating a mess.

Link to comment
Share on other sites

To get a syntax error, I should at least put the wrong code.  :P

 

Anyways, this is what I am trying.

 

<?php

$image = "<img src="images/flags/{$row_rsPilots['country']}.gif" alt="" name="Flag" width="20" height="20" />";

$link = "http://www.domain.com/{$row_rsPilots['country']}";

?>

 

<?php if (isset(($rsPilots['country']));

{ echo <a href="?><?php echo $link; ?>"><?php echo $image; ?><?php</a>;

?>

Link to comment
Share on other sites

You still haven't defined your problem very well, so I hope this is what you're talking about.

 

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

Link to comment
Share on other sites

You can also write it like

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

which gets rid of the escaped double quotes and looks cleaner (IMHO).

 

Ken

Link to comment
Share on other sites

Why did you change the code I posted and remove the escaping backslashes before the inner double quotes? Did you think I just put those there to mess with you or something? No wonder you can't get it to work.

Oopss!!!!

I thought those were not suppose to be there so I erased all manually. :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.