Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 5th, 2004, 09:36 AM
Authorized User
 
Join Date: Jul 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default random image display

in a folder I have 5 images named:
add1.jpg, add2.jpg, add3.jpg, add4.jpg, add5.jpg

now I want to display random image when user click refresh or new visitor come to that page.
I have written this code
<?php
$add="add";
$add .= rand(1,5);
$add .=".jpg";
echo "<img border='0' src='$add' width='450' height='50'>";
?>
but i seen that this code always shows one image only

Please tell me how I can do it.

__________________
Best Regard:
Md. Zakir Hossain (Raju)

www.rajuru.xenexbd.com - my blog with PHP scripts, PHP Book Review and many more
 
Old September 10th, 2004, 05:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

hey

i tried your code and it works totally fine... remember that you are using the rand() function, which generates numbers from 1 to 5, sometimes number occurrences can be same.

www.campusgrind.com the college portal
 
Old September 10th, 2004, 07:34 AM
Authorized User
 
Join Date: Jul 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default

Dear thanks for reply,
But I tried using a larger inverval. Such as
rand(1,500)

I see the same number always
even I tried from network.
It shows same number all pcs

what can I do now


 
Old September 10th, 2004, 09:42 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Looks like your code should work but try this anyway.

Code:
function writeRandomAd()
{
    $imgs = Array("add1.jpg","add2.jpg","add3.jpg","add4.jpg","add5.jpg");
    shuffle($imgs);
    echo "<img src='$imgs[0]' alt='click here!'/>";
HTH,

Snib

<><





Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload image-create & save thumbnail-display image angshujit ASP.NET 2.0 Professional 6 July 11th, 2013 10:34 PM
display random items from xml file rahimzai XML 2 November 26th, 2006 06:47 PM
Display a random record for 24 hours palvin SQL Language 6 February 6th, 2006 10:36 AM
display random record from access database jialin PHP Databases 1 December 2nd, 2005 09:18 PM
Display Random Number Every 2 seconds johnfatz2005 Java GUI 1 December 2nd, 2004 02:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.