Page 1 of 1

link not being generated correctly

Posted: Mon Aug 25, 2003 10:51 am
by meandrew
I am having a little problem with a bit of simple code!

Basically I am using this

Code: Select all

<?
/* Image here */
echo "<img src="$Relative/images/countyad/".$CountyName .".gif">";
/* Image will END here */	
?>
to display an image specific to a selected CountyName simple enough.

What I would like to do is make the image into a link :) But this is where the problem is ocurring :(


this is the code:

Code: Select all

<?
/* Image here */
echo '<A HREF="www.link.site.com"><img src=''$Relative/images/countyad/'.$CountyName.' .gif''></A>';
/* Image will END here */	
?>
I have made lots of different changes but alas no joy.

http://www.link.site.com/$Relative/imag ... sex%20.gif

and tyhis is the closest I get to the link displaying and the image no where to be seen. I think it is because there is a perceived space in the code?

At this moment in time I would be happy with just getting a fixed link with each county whilst I will eventually want to link to respective county names, but I'll tackle that later, unless someone can point me in the right direction :)

Thanks for your time guys
Andrew

Posted: Mon Aug 25, 2003 11:20 am
by volka
you might try to set up the variables first then simply output them as needed, e.g.

Code: Select all

<html>
	<head>
		<title>County Image Test</title>
	</head>
	<body>
<?php
$Relative = '..';
$CountyName = 'TestCounty';
$CountyLink = 'http://www.TestCoun.ty';

$CountyImgUrl = $Relative . '/images/countyad/' . $CountyName;
?>
		<a href="<?php $CountyLink; ?>">
			<img src="<?php echo $CountyImgUrl; ?>.gif" alt="<?php echo $CountyName; ?>"> />
		</a>
	</body>
</html>

Posted: Mon Aug 25, 2003 2:38 pm
by meandrew
this is alot closer to the solution as the image displays, albeit with a big dark border!

The problem with this snippet is the and this is bizzare, the $CountyLink does not register at all, which is very strange indeed.

Code: Select all

<?php 
$Relative = 'http://www.punterspower.co.uk'; 
$CountyName = $CountyName; 
$CountyLink = 'http://www.businessa2z.co.uk/about.php'; 
$CountyImgUrl = $Relative . '/images/countyad/' . $CountyName; 
?> 
      <a href="<?php $CountyLink; ?>"> 
         <img src="<?php echo $CountyImgUrl; ?>.gif" alt="<?php echo $CountyName; ?>"> 
      </a>
I took away the extra /> as they appear to be doing nothing at all :)

Any ideas what is casuing non recognition of the CountyLink variable?

Andrew

first country link

Posted: Mon Aug 25, 2003 3:28 pm
by phpScott
your first <a href="<?php $CountyLink; ?>"> has no echo or print statement.


hopefully that will fix it.

phpScott

Posted: Mon Aug 25, 2003 4:00 pm
by pootergeist
php doesn't parse variables echoed in single quotes, only in double

$variable = 'test';
echo '$variable' => $variable
echo "$variable" => test

you'd either want to concatenate the variable within a single quoted echo (as many people do, myself included)
echo 'some html' .$variable. ' more html';
or use double quotes and escape sequencers.

the reason the image has a nice border is plain html

<a href=""><img src="...." border="0" /></a>

or within a style sheet

img { border: 0px; }

Posted: Mon Aug 25, 2003 6:30 pm
by volka
<a href="<?php $CountyLink; ?>">
oops, my fault. Haven't tested the snippet

Posted: Mon Aug 25, 2003 6:51 pm
by JAM
To answer your first problem (and as pootergeist mentioned)

Code: Select all

<? 
/* Image here */ 
echo '<A HREF="www.link.site.com"><img src="'.$Relative.'/images/countyad/'.$CountyName.'.gif"></A>'; 
/* Image will END here */
?>
...

Posted: Tue Aug 26, 2003 11:11 am
by m3rajk
why not move to heredocs?

Code: Select all

<?php
/* set up all the stuff you need for the page or the stuff to find the   functions. include anny functions to include. if the latter include include variables in EACH function. this example is based on the former */

$var1 ='something'
$var2 ='something else'

echo <<<END
<!-- head info -->
<!-- some amount of body stuff -->
a href="$var1"><img src="$var2"></a>
<!-- some more body -->
END;
?>
it may be easier to do it like that in the long run. i know i found it more efficient, so i switched to it from popping in and out of php