|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit@flexiwebhost.com>
wrote: > >> It returns null, which brings up a blank image. > >then you can simply do something such as:- > ><?PHP >$image = getRandomImage('LL/'); >if (is_null($image)) >{ > $image = '';// Set to the image you wish >} >echo "<img src='$image' height=90 width=120 alt='LL'>"; >?> > >in the if statement place the path and name of the image you want to use as >the image that will be displayed if nothing is returned from the function. > When I use this: <?php $image = getRandomImage('LL/'); if (is_null($image)) { $image = 'none.jpg';// Set to the image you wish } echo "<img src='$image' height=90 width=120 alt='LL'>"; ?> and pull up the Web page I look at the source and I see this: <img src='' height=90 width=120 alt='LL'> As you can see the 'none.jpg' default file is not coded into the resulting HTML. Any idea why? Regards, Fred |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Fred Atkinson wrote:
> On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit@flexiwebhost.com> > wrote: > >>> It returns null, which brings up a blank image. >> then you can simply do something such as:- >> >> <?PHP >> $image = getRandomImage('LL/'); >> if (is_null($image)) >> { >> $image = '';// Set to the image you wish >> } >> echo "<img src='$image' height=90 width=120 alt='LL'>"; >> ?> >> >> in the if statement place the path and name of the image you want to use as >> the image that will be displayed if nothing is returned from the function. >> > > When I use this: > > <?php > $image = getRandomImage('LL/'); > if (is_null($image)) > { > $image = 'none.jpg';// Set to the image you wish > } > echo "<img src='$image' height=90 width=120 alt='LL'>"; > ?> > > and pull up the Web page I look at the source and I see this: > <img src='' height=90 width=120 alt='LL'> > > As you can see the 'none.jpg' default file is not coded into > the resulting HTML. > > Any idea why? > > Regards, > > > > Fred > Because it's returning an empty string - which is NOT the same as null. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Thu, 30 Aug 2007 00:14:36 -0400, Jerry Stuckle
<jstucklex@attglobal.net> wrote: >Fred Atkinson wrote: >> On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit@flexiwebhost.com> >> wrote: >> >>>> It returns null, which brings up a blank image. >>> then you can simply do something such as:- >>> >>> <?PHP >>> $image = getRandomImage('LL/'); >>> if (is_null($image)) >>> { >>> $image = '';// Set to the image you wish >>> } >>> echo "<img src='$image' height=90 width=120 alt='LL'>"; >>> ?> >>> >>> in the if statement place the path and name of the image you want to use as >>> the image that will be displayed if nothing is returned from the function. >>> >> >> When I use this: >> >> <?php >> $image = getRandomImage('LL/'); >> if (is_null($image)) >> { >> $image = 'none.jpg';// Set to the image you wish >> } >> echo "<img src='$image' height=90 width=120 alt='LL'>"; >> ?> >> >> and pull up the Web page I look at the source and I see this: >> <img src='' height=90 width=120 alt='LL'> >> >> As you can see the 'none.jpg' default file is not coded into >> the resulting HTML. >> >> Any idea why? >> >> Regards, >> >> >> >> Fred >> > >Because it's returning an empty string - which is NOT the same as null. As you can see, I am defining the string as none.jpg. I can't imagine why it still thinks it is null. Fred |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Fred Atkinson wrote:
> On Thu, 30 Aug 2007 00:14:36 -0400, Jerry Stuckle > <jstucklex@attglobal.net> wrote: > >> Fred Atkinson wrote: >>> On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit@flexiwebhost.com> >>> wrote: >>> >>>>> It returns null, which brings up a blank image. >>>> then you can simply do something such as:- >>>> >>>> <?PHP >>>> $image = getRandomImage('LL/'); >>>> if (is_null($image)) >>>> { >>>> $image = '';// Set to the image you wish >>>> } >>>> echo "<img src='$image' height=90 width=120 alt='LL'>"; >>>> ?> >>>> >>>> in the if statement place the path and name of the image you want to use as >>>> the image that will be displayed if nothing is returned from the function. >>>> >>> When I use this: >>> >>> <?php >>> $image = getRandomImage('LL/'); >>> if (is_null($image)) >>> { >>> $image = 'none.jpg';// Set to the image you wish >>> } >>> echo "<img src='$image' height=90 width=120 alt='LL'>"; >>> ?> >>> >>> and pull up the Web page I look at the source and I see this: >>> <img src='' height=90 width=120 alt='LL'> >>> >>> As you can see the 'none.jpg' default file is not coded into >>> the resulting HTML. >>> >>> Any idea why? >>> >>> Regards, >>> >>> >>> >>> Fred >>> >> Because it's returning an empty string - which is NOT the same as null. > > As you can see, I am defining the string as none.jpg. I can't > imagine why it still thinks it is null. > > > > > Fred > Read what I said again. And no, you're not. You're checking: if (is_null($image)) And the test is false because it's not null. So you're not setting it to none.jpg. It never was null, and PHP doesn't think it's null. NULL IS NOT THE SAME AS AN EMPTY STRING! -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
> As you can see, I am defining the string as none.jpg. I can't > imagine why it still thinks it is null. As Jerry has pointed out. NULL and an empty string are 2 complete different things. If the code I supplied is not working then the function is not returning NULL it is returning an empty string. That being the case change the is_null function to the empty function <?PHP $image = getRandomImage('LL/'); if (empty($image)) { $image = '';// Set to the image you wish } echo "<img src='$image' height=90 width=120 alt='LL'>"; ?> |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Sun, 2 Sep 2007 16:52:26 +0100, "peter" <submit@flexiwebhost.com>
wrote: > >> As you can see, I am defining the string as none.jpg. I can't >> imagine why it still thinks it is null. > >As Jerry has pointed out. NULL and an empty string are 2 complete different >things. If the code I supplied is not working then the function is not >returning NULL it is returning an empty string. > >That being the case change the is_null function to the empty function > ><?PHP >$image = getRandomImage('LL/'); >if (empty($image)) >{ > $image = '';// Set to the image you wish >} >echo "<img src='$image' height=90 width=120 alt='LL'>"; >?> > Gentlemen: I thank you. Your revision above didn't quite fit my application due to a quirk in the program being called up (that I didn't show you). But after I revised it a slight little bit, it did the job just perfectly. Thank you both for your . I got it working just fine. My best regards, :-) Fred Atkinson |
|
![]() |
| Outils de la discussion | |
|
|