0

Hi there guys, I wonder if you could help. I have a small issue when using the below code with certain browsers mainly with the echo image part. at the moment the code checks to see if there is an image name in the field and then appends to the image src. Everything works fine in firefox, but if you use anything else when the fetch is run I get left with a null image block.

Is there any way I can only echo that row if there is a value e.g. image.jpg?

Thanks again in advance, probably something so simple I am just to tired to see at the moment lol

Rich

 <?php 



                        if(!mysql_num_rows($result) || mysql_num_rows($result) == 0)
                        { 
                            echo "<b>Unfortunately you have not made any blessing entries.  Please add your magic blessing<br /><br />"; 
                        } 
                    while($row = mysql_fetch_array($result)){
                        echo "";
                        echo '<h3>' .$row['title'] .'</h3> ' ; echo "";
                        echo "<br />";
                        echo "". wordwrap($row['blessing1'], 90, "<br />\n");echo "<br />";
                        echo "<br />";
                        echo "". wordwrap($row['blessing2'], 90, "<br />\n");echo "<br />";
                        echo "<br />";
                        echo "". wordwrap($row['blessing3'], 90, "<br />\n");echo "<br />";
                        echo "<a class='fancybox' href=\"memberFiles/$userid/blessings/".$row['photo']."\">   <img src=\"memberFiles/$userid/blessings/".$row['photo']."\" width=500 hspace=0 vspace=0 border=0></a>";echo "<br />"; 


                        echo "<br />";echo '' .$row['datepublished'] .'<br />' ;
                        echo "<br />";
                        echo "<hr />";
                    }

                   echo "<br />";
                    // pagination
                    echo $paginate;
                    ?>
3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by richlacey
0

If I understand your question correctly you should be able to use is_null to check the field has a value before printing.

example:

while($row = mysql_fetch_array($result)){
    ...
    if (!is_null($row['photo']))
        //print image
    ...

Edited by |-|x

0

In my experience is_null doesn't work for values pulled from a database. MySQL null is not equivelent to PHP null. Null column values come across as an empty string so checking it against an empty string like below should help you out:

if ( $row['photo'] !== '' ) {
    //image here
}
0

I think it depends on how you access the data from the mysql_result.

The mysql_fetch_array man page states:

Note: This function sets NULL fields to the PHP NULL value.

0

Interesting, probably never found that out because I don't use mysql_fetch_array() very much. Guess I was wrong.

0

Thanks guys this worked perfectly, cant see the wood for the trees haha

have a good one

Rich

    if ( $row['photo'] !== '' ) {
    //image here
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.