PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
chrisk1152
Forum Newbie
Posts: 9 Joined: Wed Apr 02, 2008 4:02 pm
Post
by chrisk1152 » Wed Apr 02, 2008 4:08 pm
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?
kishanprasad
Forum Newbie
Posts: 16 Joined: Mon Feb 25, 2008 5:20 pm
Post
by kishanprasad » Wed Apr 02, 2008 4:45 pm
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
chrisk1152
Forum Newbie
Posts: 9 Joined: Wed Apr 02, 2008 4:02 pm
Post
by chrisk1152 » Wed Apr 02, 2008 4:56 pm
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.
pisio
Forum Newbie
Posts: 5 Joined: Wed Apr 02, 2008 4:55 pm
Post
by pisio » Wed Apr 02, 2008 5:04 pm
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>";
?>
chrisk1152
Forum Newbie
Posts: 9 Joined: Wed Apr 02, 2008 4:02 pm
Post
by chrisk1152 » Wed Apr 02, 2008 5:33 pm
<?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
Last edited by
chrisk1152 on Wed Apr 02, 2008 5:35 pm, edited 1 time in total.
pisio
Forum Newbie
Posts: 5 Joined: Wed Apr 02, 2008 4:55 pm
Post
by pisio » Wed Apr 02, 2008 5:34 pm
$banner[4]['link'] = './smash.html ';
$image[4]['img'] = './super-smash-flash-sml.gif ';
chrisk1152
Forum Newbie
Posts: 9 Joined: Wed Apr 02, 2008 4:02 pm
Post
by chrisk1152 » Wed Apr 02, 2008 5:39 pm
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>
pisio
Forum Newbie
Posts: 5 Joined: Wed Apr 02, 2008 4:55 pm
Post
by pisio » Wed Apr 02, 2008 5:52 pm
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>";
?>
Last edited by
John Cartwright on Wed Apr 02, 2008 9:13 pm, edited 1 time in total.
Reason: Please use [code=php][/code] tags when posting code
chrisk1152
Forum Newbie
Posts: 9 Joined: Wed Apr 02, 2008 4:02 pm
Post
by chrisk1152 » Wed Apr 02, 2008 10:21 pm
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?
chrisk1152
Forum Newbie
Posts: 9 Joined: Wed Apr 02, 2008 4:02 pm
Post
by chrisk1152 » Thu Apr 03, 2008 9:12 am
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>";
?>
Last edited by
chrisk1152 on Thu Apr 03, 2008 6:12 pm, edited 1 time in total.
chrisk1152
Forum Newbie
Posts: 9 Joined: Wed Apr 02, 2008 4:02 pm
Post
by chrisk1152 » Thu Apr 03, 2008 11:27 am
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?