Forum Moderators: coopster

Message Too Old, No Replies

The Links Won't Stop!

This PHP script is making everything beneath it a hyperlink

         

shimeal

5:11 am on Feb 10, 2005 (gmt 0)

10+ Year Member



The following code is turning the text beneath it (starting with the <h2>about</h2>) into hyperlinks. Can anyone tell me why it this code is doing this?

<h2>Sponsors</h2>
<div id="buttonalign">
<?

srand((float) microtime() * 10000000);

$image[1]['pic']='/buttons/cxsuppliesbutton.gif';
$image[1]['link']='http://www.....com';

$image[2]['pic']='/buttons/obsbutton.gif';
$image[2]['link']='http://www.....com';

$rn = array_rand($image);

echo '<a href="'.$image[$rn]['link'].'" target="_blank">';
echo '<img src="'.$image[$rn]['pic'].'"border=0>';

?>
</div>

<h2>About</h2>

dmmh

5:19 am on Feb 10, 2005 (gmt 0)

10+ Year Member



you dont have a closing tag for the link
like </a>
another error would be that you dont use double quotes for the img tag border property
thats not the reason for the error, this would be the left-out </a> tag, but it is just bad style coding :)

also, Im not saying to adopt this, but in my personal experience it is much easier, especially so with URLs to switch between PHP and HTML when you need it. This is how I do it:

<h2>Sponsors</h2>
<div id="buttonalign">
<?
srand((float) microtime() * 10000000);

$image[1]['pic']='/buttons/cxsuppliesbutton.gif';
$image[1]['link']='http://www.....com';

$image[2]['pic']='/buttons/obsbutton.gif';
$image[2]['link']='http://www.....com';

$rn = array_rand($image);?>

<a href="<? echo $image[$rn]['link'];?>" target="_blank"><img src="<? echo $image[$rn]['pic'];?>" border="0"></a>
</div>

<h2>About</h2>

shimeal

5:25 am on Feb 10, 2005 (gmt 0)

10+ Year Member



Rock on - thanks so much!

dmmh

5:30 am on Feb 10, 2005 (gmt 0)

10+ Year Member



pleasure :)