thumbliner Posted April 25, 2011 Share Posted April 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/ Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 So are there only 2 possible countries, USA and Germany, or is it actually every country? Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206011 Share on other sites More sharing options...
thumbliner Posted April 25, 2011 Author Share Posted April 25, 2011 My forms allow around 120 countries and I have flags for all. That is not the problem. Even if it is infinite, lets assume I have flags for all. I am more concerned about the link www.domain.com/country Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206015 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206023 Share on other sites More sharing options...
thumbliner Posted April 25, 2011 Author Share Posted April 25, 2011 :-\ I am new to PHP but not new to common sense. 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. Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206028 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 So then, your problem is actually a syntax error? You didn't even imply that in the OP. How about posting the actual relevant code, and any errors it's generating. Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206032 Share on other sites More sharing options...
thumbliner Posted April 25, 2011 Author Share Posted April 25, 2011 To get a syntax error, I should at least put the wrong code. 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>; ?> Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206041 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206104 Share on other sites More sharing options...
thumbliner Posted April 26, 2011 Author Share Posted April 26, 2011 Have a look at the attachment, please. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206252 Share on other sites More sharing options...
rog1121 Posted April 26, 2011 Share Posted April 26, 2011 Within echo use the single quote like this ' and not the Double quotes that look like this " Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206261 Share on other sites More sharing options...
Pikachu2000 Posted April 26, 2011 Share Posted April 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206264 Share on other sites More sharing options...
kenrbnsn Posted April 26, 2011 Share Posted April 26, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206282 Share on other sites More sharing options...
thumbliner Posted April 26, 2011 Author Share Posted April 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206488 Share on other sites More sharing options...
thumbliner Posted April 26, 2011 Author Share Posted April 26, 2011 Alright, problem solved. Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/234684-trouble-with-if/#findComment-1206560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.