• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

PHP rplace number array with images when printing

Hi, I have the code below in PHP which is pretty simple. I'm trying to do a random lotto picker. I have all the images in a folder "images/numbers/1.gif" all the way up to 45.gif

I know this should be pretty simple to implement but I'm not as well versed in PHP.

I want the end result to print out the corresponding image numbers instead of text.

Any help much appreciated :) Thanks
<?php
$balls = range(1,45);
shuffle($balls);
$pick = array_slice($balls,0,6);
$drawn = implode(", ",$pick);
sort($pick);
$ascend = implode(" ... ",$pick);
 
print ("<center><b>Your Lucky Quickpick</b><br>");
print $drawn;
print ("<br><br>");
print ("<center>In ascending order ...<br>");
print $ascend;
print ("<br><br>");
print ("<center>Good Luck :)");
 
?>

Open in new window

0
keevo
Asked:
keevo
  • 7
  • 3
1 Solution
 
unassassinableCommented:
Im also not well versed in PHP, but would something like this work?  youd have to integrate the print function in there...

$rand=rand(1,45);
$name="images/numbers/".$rand.".gif";
include_once($name); ?>
0
 
keevoAuthor Commented:
i'll try this now and let you know. thanks for quick response
0
 
unassassinableCommented:
Yeah you bet.  Thats a piece of code I use on my site to randomly show 1 of 5 different divs.  I just replaced the directories and the extensions (to .gif rather than .php for your case).  you can see how it works here:

http://equinoxits.com/home.php

just hit the refresh button a few times
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
keevoAuthor Commented:
I'm pretty sure this is the code :) it will work but at the moment it is printing out the text location of the image and not retrieving the actual image

$rand = range(1,45);
$name= "images/numbers/".$rand.".gif";

print= $name;

I tried

$name= $_SERVER['images/numbers/$rand.gif'];

but no joy

0
 
unassassinableCommented:
Could you use something like this?  Not sure what the application is your using,  if its a web app, this would work.  

<img src="images/<?php echo(rand(1,45)); ?>.jpg" alt="" />

heres a working example:

http://equinoxits.com/lotto.php
0
 
keevoAuthor Commented:
i'm still a small bit lost. was trying something like this:

$images = array(
        1 => '1.gif',
        2 => '2.gif',
        3 => '3.gif',
        4 => '4.gif',
      5 => '5.gif',
        6 => '6.gif',
        7 => '7.gif',
        8 => '8.gif',
        9 => '9.gif',
      10 => '10.gif',
        11 => '11.gif',
        12 => '12.gif',
        13 => '13.gif',
        14 => '14.gif',
      15 => '15.gif',
        16 => '16.gif',
        17 => '17.gif',
        18 => '18.gif',
        19 => '19.gif',
            20 => '20.gif',
        21 => '21.gif',
        22 => '22.gif',
        23 => '23.gif',
        24 => '24.gif',
        25 => '25.gif',
            26 => '26.gif',
        27 => '27.gif',
        28 => '28.gif',
        29 => '29.gif',
        30 => '30.gif',
        31 => '31.gif',
            32 => '32.gif',
        33 => '33.gif',
        34 => '34.gif',
        35 => '35.gif',
        36 => '36.gif',
        37 => '37.gif',
            38 => '38.gif',
            39 => '39.gif',
        40 => '40.gif',
        41 => '41.gif',
        42 => '42.gif',
            43 => '43.gif',
            44 => '44.gif',
            45 => '45.gif',
    );

shuffle($images);
$pick = array_slice($images,0,6);
$drawn = implode(", ",$pick);
sort($pick);
$ascend = implode(" ... ",$pick);

print ("<center><b>Your Lucky Quickpick</b><br>");
print $drawn;
print ("<br><br>");
print ("<center>In ascending order ...<br>");
print $ascend;
print ("<br><br>");
print ("<center>Good Luck :)");



resulting in

Your Lucky Quickpick
27.gif, 9.gif, 5.gif, 7.gif, 15.gif, 35.gif

In ascending order ...
15.gif ... 27.gif ... 35.gif ... 5.gif ... 7.gif ... 9.gif


lol...

            
0
 
keevoAuthor Commented:
hmmmmm ok i have the numbers and a corresponding image array but don't know how to display the images

$balls = range(1,45);
$images = array(
        1 => '1.gif',
        2 => '2.gif',
        3 => '3.gif',
        4 => '4.gif',
            5 => '5.gif',
        6 => '6.gif',
        7 => '7.gif',
        8 => '8.gif',
        9 => '9.gif',
            10 => '10.gif',
        11 => '11.gif',
        12 => '12.gif',
        13 => '13.gif',
        14 => '14.gif',
            15 => '15.gif',
        16 => '16.gif',
        17 => '17.gif',
        18 => '18.gif',
        19 => '19.gif',
            20 => '20.gif',
        21 => '21.gif',
        22 => '22.gif',
        23 => '23.gif',
        24 => '24.gif',
        25 => '25.gif',
            26 => '26.gif',
        27 => '27.gif',
        28 => '28.gif',
        29 => '29.gif',
        30 => '30.gif',
        31 => '31.gif',
            32 => '32.gif',
        33 => '33.gif',
        34 => '34.gif',
        35 => '35.gif',
        36 => '36.gif',
        37 => '37.gif',
            38 => '38.gif',
            39 => '39.gif',
        40 => '40.gif',
        41 => '41.gif',
        42 => '42.gif',
            43 => '43.gif',
            44 => '44.gif',
            45 => '45.gif',
    );
shuffle($balls);
$pick = array_slice($balls,0,6);
$drawn = implode(", ",$pick);
sort($pick);
$ascend = implode(" ... ",$pick);

print ("<center><b>Your Lucky Quickpick</b><br>");
print $drawn;
0
 
keevoAuthor Commented:
lost now :(
0
 
thehagmanCommented:

<?
$balls = range(1,45);
shuffle($balls);
$pick = array_slice($balls, 0 6);
sort($pick);
?>
<h1>Your lucky numbers</h1>
<div>
<?
foreach ($pick as $number) {
?>
<img src="/images/<?=$number?>.gif" alt="<?=$number"/>
<?
}
?>
</div>
<p>Good luck!</p>

Open in new window

0
 
keevoAuthor Commented:
absolute genius :)

you even got them to come out in error............

thanks all for your help.

if you want to see what you helped create check http://apps.facebook.com/quickpicker/

now all i need is the lotto numbers lol :)
0
 
keevoAuthor Commented:
i meant to say order not error
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now