Page 1 of 1

Rotating a link with a .gif

Posted: Wed Apr 02, 2008 4:08 pm
by chrisk1152
I have this so far and I am having issues with the coding. I'm not getting the links to show up.

Code: Select all

 
//Read the file into an array
$gamesArray = file("gamesfile.txt");
 
//Pick a random element from the array
$selectedGame = array_rand($gamesArray);
 
//Separate the image filename from the URL link using the explode()function
//This puts the image into $selectedArray[0]
//and puts the URL into $selectedArray[1]
$selectedArray = explode("|", $selectedGame);
 
//Get fancy by finding the dimensions of the image
$imgData = getimagesize($selectedArray[0]);
 
//Build the HTML
print "<a href=\"{$selectedArray[1]}\">\n";
print "<img src=\"{$selectedArray[0]}\" {$imgData[3]} title=\"Game image\" alt=\"Game image\">\n";
print "</a>\n";  
The gamesfile.txt looks like

pacman.gif|http://www.pacmanglory.com
mspacman.gif|http://www.mspacman.com
spaceinvaders.gif|http://www.spaceinvadersfanatics.org
asteroids.gif|http://www.asteroidlovers.com

These are only examples. but the links are the same. All I'm getting is a box that says Game Image in it and liks back to the same page. Does anyone have any ideas?

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 4:45 pm
by kishanprasad
HI
array_rand returns the key rather than the value ...so in your code

instead of $selectedArray = explode("|", $selectedGame);

use

$selectedArray = explode("|", $gamesArray[$selectedGame]);

this will work....

Kishan

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 4:56 pm
by chrisk1152
I changed the line but it's still doing the same thing.

http://www.restoredsolia.org/welcome.php here is a link to the page.


When i look at the page source it give me this

<p align="center">
<a href="">
<img src="" title="Game image" alt="Game image">

It's not looking in the file that I created to link it to.

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 5:04 pm
by pisio

Code: Select all

<?php
 
$number = rand(1,3);
#######
$banner[1]['link'] = 'http://web-tourist.net';
$banner[2]['link'] = 'http://google.com';
$banner[3]['link'] = 'http://abv.bg';
 
$image[1]['img'] = './a.gif';
$image[2]['img'] = './a.gif';
$image[3]['img'] = './a.gif';
 
echo "<a href=\"$banner[$number]['link']\" target=\"_blank\">";
echo "<img src=\"$image[$number]['img']\" border=\"0\" />";
echo "</a>";
 
?>
:?:

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 5:33 pm
by chrisk1152
<?php
$number = rand(1,4);
#######
$banner[1]['link'] = './tanks.html';
$banner[2]['link'] = './taxi.html';
$banner[3]['link'] = './spaceinvaders.html';
$banner[4]['link'] = './smash.html


$image[1]['img'] = './tanks_sml.gif';
$image[2]['img'] = './taxi.jpg';
$image[3]['img'] = './spaceinvaders_sml.gif';
$image[4]['img'] = './super-smash-flash-sml.gif


echo "<a href=\"$banner[$number]['link']\" target=\"iframe\">";
echo "<img src=\"$image[$number]['img']\" border=\"0\" />";
echo "</a>";
?>
</p>


gets me:

Parse error: syntax error, unexpected T_STRING in /home/content/n/a/v/navadia/html/welcome.php on line 47

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 5:34 pm
by pisio
$banner[4]['link'] = './smash.html';
$image[4]['img'] = './super-smash-flash-sml.gif';

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 5:39 pm
by chrisk1152
that fixed me getting an error.. Sorry i missed that.

now I get nothing when I goto the page it just doesn't show up.

http://www.restoredsolia.org/welcome.php

Here is the view source codeing:

<p align="center">
<a href="Array['link']" target="iframe"><img src="Array['img']" border="0" /></a></p>

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 5:52 pm
by pisio

Code: Select all

<?php
$number = rand(1,4);
#######
$banner[1]['link'] = 'http://www.restoredsolia.org/tanks.html';
$banner[2]['link'] = 'http://www.restoredsolia.org/taxi.html';
$banner[3]['link'] = 'http://www.restoredsolia.org/spaceinvaders.html';
$banner[4]['link'] = 'http://www.restoredsolia.org/smash.html';
 
 
$image[1]['img'] = 'http://www.restoredsolia.org/tanks_sml.gif';
$image[2]['img'] = 'http://www.restoredsolia.org/taxi.jpg';
$image[3]['img'] = 'http://www.restoredsolia.org/spaceinvaders_sml.gif';
$image[4]['img'] = 'http://www.restoredsolia.org/super-smash-flash-sml.gif';
 
 
echo '<a href='.$banner[$number]['link'].'>';
echo '<img src='.$image[$number]['img'].' border="0" />';
echo "</a>";
?>

Re: Rotating a link with a .gif

Posted: Wed Apr 02, 2008 10:21 pm
by chrisk1152

Code: Select all

 
<?php
$number = rand(1,4);
#######
$banner[1]['link'] = 'http://www.restoredsolia.org/tanks.html';
$banner[2]['link'] = 'http://www.restoredsolia.org/taxi.html';
$banner[3]['link'] = 'http://www.restoredsolia.org/spaceinvaders.html';
$banner[4]['link'] = 'http://www.restoredsolia.org/smash.html';
 
 
$image[1]['img'] = 'http://www.restoredsolia.org/tanks_sml.gif';
$image[2]['img'] = 'http://www.restoredsolia.org/taxi.jpg';
$image[3]['img'] = 'http://www.restoredsolia.org/spaceinvaders_sml.gif';
$image[4]['img'] = 'http://www.restoredsolia.org/super-smash-flash-sml.gif';
 
 
echo '<a href='.$banner[$number]['link'].'>';
echo '<img src='.$image[$number]['img'].' border="0" />';
echo "</a>";
?>
 
Is there any way to get this to load into an Iframe? Also is there a way to add what the game is so that the users can see what game it is?

Re: Rotating a link with a .gif

Posted: Thu Apr 03, 2008 9:12 am
by chrisk1152
ok I've figured out to load it into an iframe.

Now my question is how would you get it to have the Image with text under it describing it?

Code: Select all

 
<?php
$number = rand(1,4);
#######
$banner[1]['link'] = 'http://www.restoredsolia.org/tanks.html';
$banner[2]['link'] = 'http://www.restoredsolia.org/taxi.html';
$banner[3]['link'] = 'http://www.restoredsolia.org/spaceinvaders.html';
$banner[4]['link'] = 'http://www.restoredsolia.org/smash.html';
 
 
$image[1]['img'] = 'http://www.restoredsolia.org/tanks_sml.gif';
$image[2]['img'] = 'http://www.restoredsolia.org/taxi.jpg';
$image[3]['img'] = 'http://www.restoredsolia.org/spaceinvaders_sml.gif';
$image[4]['img'] = 'http://www.restoredsolia.org/super-smash-flash-sml.gif';
 
 
echo '<a href='.$banner[$number]['link'].'>';
echo '<img src='.$image[$number]['img'].' border="0" />';
echo "</a>";
?>
 
 

Re: Rotating a link with a .gif

Posted: Thu Apr 03, 2008 11:27 am
by chrisk1152
ok here is what I've got so far,

Code: Select all

 
<?php
$number = rand(1,4);
#######
$game[1]['link'] = 'http://www.restoredsolia.org/tanks.html';
$game[2]['link'] = 'http://www.restoredsolia.org/taxi.html';
$game[3]['link'] = 'http://www.restoredsolia.org/spaceinvaders.html';
$game[4]['link'] = 'http://www.restoredsolia.org/smash.html';
 
$image[1]['img'] = 'http://www.restoredsolia.org/tanks_sml.gif';
$image[2]['img'] = 'http://www.restoredsolia.org/taxi.jpg';
$image[3]['img'] = 'http://www.restoredsolia.org/spaceinvaders_sml.gif';
$image[4]['img'] = 'http://www.restoredsolia.org/super-smash-flash-sml.gif';
 
$title[1]['img'] = 'Tanks';
$title[2]['img'] = 'Taxi';
$title[3]['img'] = 'Space Invaders';
$title[4]['img'] = 'Super Smash';
 
echo '<a href='.$game[$number]['link'].'>';
echo '<img src='.$image[$number]['img'].' border="2" /><br />';
echo '<center> $title[$number]['img'] <center>';
echo "</a>";
?> 
 
but the line

Code: Select all

 
echo '<center> $title[$number]['img'] <center>';
 
throws out an error.

How can I fix this?