Re: isset or ! isset what is my problem?
| From: | Micah Stevens | Date: | Tue, 03 Jan 2006 03:59:03 +0000 |
| Subject: | Re: isset or ! isset what is my problem? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-40958@lists.php.net to get a copy of this message | ||
NULL != Not set.
isset() tests to see if the variable exists. If your variable has a null value
it is set, it DOES exist, it just has NULL for a value. You should test for a
null value if that's what you want:
if ($picture == null)
Or perhaps the empty() function might be what you're looking for.
-Micah
On Monday 02 January 2006 7:54 pm, Ralph wrote:
> I'm building a URL based on data extracted from mySQL and I want the
> text space.gif used as my default value should the variable $picture
> by NULL.
>
> The results of the code below kick back a value for $picture when it
> is set in the database, but ignores the space.gif if the database
> result is empty.
>
> If I flip the test from ! isset to isset then I get the space.gif for
> each result.
>
>
> I've had no luck searching out an answer.
>
> Thanks in advance.
>
> --------------The Code-----------------------------
> <?php do { ?>
> <img src="images/<?php
> $picture=$row_rst_screenings['Picture'];
>
> if(! isset($picture)) {
> $picture='space.gif';
> }else{
> $picture=$row_rst_screenings['Picture'];
> }
>
> echo $picture;
>
> ?>"><br>
> <p><span class="style2"><?php echo
> $row_rst_screenings['Title']; ?></
> span><br />
> <span class="style3"><?php echo $row_rst_screenings['Director'];
> ?></
> span></p>
> <p class="style4"><?php echo $row_rst_screenings['Blurb'];
> ?></p>
> <p class="style3">Showtime: <?php echo $row_rst_screenings
> ['ShowTime']; ?> <?php echo $row_rst_screenings['ShowDate'];
> ?></p>
> <p class="style3">Location: <?php echo $row_rst_screenings
> ['Location']; ?></p>
>
> <?php } while ($row_rst_screenings = mysql_fetch_assoc
> ($rst_screenings)); ?>
>
> ---------------END-----------------