473,651 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

random pic - does not ALWAYS show

i just want to show up a random pic.

<?
$files = glob("./gfx/zufall/*");
shuffle ($files);
if (count($files) < 1)
$count = count($files);
else
$count = 1;
for ($i = 0; $i < $count; $i ++)
{
$file = $files[$i];
echo "<a href='index.php '><img src='$file' height='341'
width='634' border='0'></a>";
}
?>

it works fine, just ocasionally, it shows NO pic.
whats wrong? that is, how can i solve it?

Jan 25 '07 #1
5 1515

"Tobi Hammert" <sp*******@gmai l.comwrote in message
news:11******** *************@a 75g2000cwd.goog legroups.com...
>i just want to show up a random pic.

<?
$files = glob("./gfx/zufall/*");
shuffle ($files);
if (count($files) < 1)
$count = count($files);
else
$count = 1;
for ($i = 0; $i < $count; $i ++)
{
$file = $files[$i];
echo "<a href='index.php '><img src='$file' height='341'
width='634' border='0'></a>";
}
?>

it works fine, just ocasionally, it shows NO pic.
whats wrong? that is, how can i solve it?
On those rare occasions when it doesn't work, have you looked at the source
code to see what the output was? print_r($files) ; to see if . and .. are
included in the file list. If they are, those might be casusing your
problem. If not, see the output when it doesn't work and try to figure what
went wrong. Another guess would be non-ascii characters in filenames don't
translate to url, like characters with umlauts or stuff like that.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi. net | rot13(xv***@bhg byrzcv.arg)
Jan 25 '07 #2
Message-ID: <11************ *********@a75g2 000cwd.googlegr oups.comfrom
Tobi Hammert contained the following:
><?
$files = glob("./gfx/zufall/*");
shuffle ($files);
if (count($files) < 1)
$count = count($files);
else
$count = 1;
for ($i = 0; $i < $count; $i ++)
{
$file = $files[$i];
echo "<a href='index.php '><img src='$file' height='341'
width='634' border='0'></a>";
}
?>

it works fine, just ocasionally, it shows NO pic.
whats wrong? that is, how can i solve it?
Occasionally you get . or .. in which case you won't see a picture. If
your files are all .jpgs, try $files = glob("./gfx/zufall/*.jpg");
Alternatively try (untested):

$files = glob("./gfx/zufall/*");
shuffle ($files);
foreach( $files as $key=>$value){
if ($value=="." || $value==".."){
unset($files[$key]);
}
}

echo "<a href='index.php '><img src='".$file[0]."' height='341'
width='634' border='0'></a>";
}
?>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jan 25 '07 #3
Message-ID: <dj************ *************** *****@4ax.comfr om Geoff
Berrow contained the following:
>
$files = glob("./gfx/zufall/*");
shuffle ($files);
foreach( $files as $key=>$value){
if ($value=="." || $value==".."){
unset($files[$key]);
}
}

echo "<a href='index.php '><img src='".$file[0]."' height='341'
width='634' border='0'></a>";
}
?>
Ummm, that should be:-

$files = glob("./gfx/zufall/*");
shuffle ($files);
foreach( $files as $key=>$value){
if ($value=="." || $value==".."){
unset($files[$key]);
}
}
echo "<a href='index.php '><img src='".$files[0]."' border='0'></a>";

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jan 25 '07 #4
Geoff Berrow wrote:
Message-ID: <dj************ *************** *****@4ax.comfr om Geoff
Berrow contained the following:
> $files = glob("./gfx/zufall/*");
shuffle ($files);
foreach( $files as $key=>$value){
if ($value=="." || $value==".."){
unset($files[$key]);
}
}

echo "<a href='index.php '><img src='".$file[0]."' height='341'
width='634' border='0'></a>";
}
?>

Ummm, that should be:-

$files = glob("./gfx/zufall/*");
shuffle ($files);
foreach( $files as $key=>$value){
if ($value=="." || $value==".."){
unset($files[$key]);
}
}
echo "<a href='index.php '><img src='".$files[0]."' border='0'></a>";
Close, Goeff. But I think you want to remove the pseudo-files before
you shuffle. What happens if after the shuffle one of them comes up as
element 0?

Just putting the shuffle() after the foreach loop should work better.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jan 25 '07 #5
found the bug - its almost embarassing ;)
was a hidden file, created prob. by dreamweaver. after i removed it,
everything worked smoothly.

thanks anyway!

Jan 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
3684
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are appreciated.
3
2392
by: Wim Roffil | last post by:
Hi, When I do a select with a limit I get always the same records. Usually this is the desidered effect. But now I want to do a random select. So every time I do a select I should get a different set of results. What is the best way to achieve this effect?
11
1822
by: Mark Rae | last post by:
Hi, My R&D department has asked me to look at threading in a Web Service written in C#, so I came up with the following code: using System; using System.ComponentModel; using System.Threading; using System.Web.Services;
3
1787
by: George Durzi | last post by:
How can I choose a random integer between to given integers? For example, I'd like to pick a random integer between 1 and 3. E.g. 1, 2, or 3 If I do Dim oRandom As New Random(1) Response.Write oRandom.Next(3)
4
1393
by: Dennis W | last post by:
I want to display a differnt message evry time a button is clicked. so I set up a aray of ms(12) so that I can asign 12 differnt strings to a labelbut I get a error . First of all can I asign a string value to a label? Im new to vb . I 'm still trying to shake the happits of basica or gwbasic trobo basic. You get the Idea. So can someone get me on the right path here. -- //Bart//
12
5218
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's RAND(). any ideas? I suppose I could use the current rancom number as the seed for the next random number. but would that really work?
2
1742
by: Steven D'Aprano | last post by:
I'm working on some functions that, essentially, return randomly generated strings. Here's a basic example: def rstr(): """Return a random string based on a pseudo normally-distributed random number. """ x = 0.0 for i in range(12): x += random.random()
13
2799
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000, or between 0 and 99999 (inclusive). Further, the I want the range to be a variable. Concretely, I would like to create the following method: unsigned long Random( unsigned long num )
13
2356
by: Bruza | last post by:
I need to implement a "random selection" algorithm which takes a list of as input. Each of the (obj, prob) represents how likely an object, "obj", should be selected based on its probability of "prob".To simplify the problem, assuming "prob" are integers, and the sum of all "prob" equals 100. For example, items = The algorithm will take a number "N", and a list as
24
7203
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me uniformly distributed and unique numbers ?
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8694
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7294
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.