Professional Web Applications Themes

Hide null from database and... - Macromedia Dynamic HTML

I'm setting up dynamic content to display regions from a database. When it displays in the window it might look something like this (the italic indicates information that is database driven). Name: Joe Brown Phone: 555-555-5555 Website: Poor Joe does not have a website, but the thing I want to do is when the database does not have a reference for a website I want to remove the text "Website:". As I am using repeating regions and some have websites I have to have it there if the database has the info. Easy way would be to include that text ...

  1. #1

    Default Hide null from database and...

    I'm setting up dynamic content to display regions from a database. When it
    displays in the window it might look something like this (the italic indicates
    information that is database driven).


    Name: Joe Brown
    Phone: 555-555-5555
    Website:



    Poor Joe does not have a website, but the thing I want to do is when the
    database does not have a reference for a website I want to remove the text
    "Website:". As I am using repeating regions and some have websites I have to
    have it there if the database has the info. Easy way would be to include that
    text in the actual database but there has to be a better way.

    I am using PHP.
    Thank you in advance for your replies.



    designome Guest

  2. #2

    Default Re: Hide null from database and...

    try something like this: First set your database up for the "website" field
    to default to null

    <?
    if ( $website == NULL) {
    echo "<div>Nothing here</div> ";
    }
    else {
    echo " Website : $website_url";
    }
    ?>

    You can reverse it and write your content however you want but that's pretty
    simple. If you're working with more than two possible field entries that could
    require different responses, use a "case switch".

    Happy Headaches...

    Z......








    znebula Guest

  3. #3

    Default Re: Hide null from database and...

    Ithink the abouve code will be working. If not you just jplace an do while loop in the code.
    Brian Guest

  4. #4

    Default Re: Hide null from database and...

    That does the trick, thank you so much. :D




    designome Guest

  5. #5

    Default Re: Hide null from database and...

    Just a little clean up. The following works, but there should be a cleaner way.



    <?
    if ( $row_rsProfiles['faculty_office'] == NULL) {
    echo "";
    }
    else {
    echo "Office: ";
    }
    ?>


    <?php if ($totalRows_rsProfiles > 0) { // Show if recordset not empty
    ?>
    <?php echo $row_rsProfiles['faculty_office']; ?>
    <?php } // Show if recordset not empty ?>

    <br />



    That's what I have so far.

    Have tried

    <?
    if ( $row_rsProfiles['faculty_office'] == NULL) {
    echo "";
    }
    else {
    echo "Office: $row_rsProfiles['faculty_office']";
    }
    ?>

    <br />


    but it does not work. Have tired a few variations but obviously have not hit
    on the correct way to do it.

    Also how can I include the break in the statement so I don't have an extra
    break if there is no content?





    Thank you again, anyone who can answer.

    designome Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139