Professional Web Applications Themes

Dynamic removal of text if field is empty using PHP - Dreamweaver AppDev

I have a mySQL database which has some fields which may, or may not be empty. I wish to display them in the following way using PHP:- Result 1; Result 2; Result 3; Result 4 and so on. My question is, if the fields for 'Result 2' and 'Result 3' are empty, can I dynamically remove the ';' so that my results read:- Result 1; Result4 instead of the results I am currently getting:- Result 1; ; ; Result 4 I would appreciate any help on this one, as I can't seem to find anything which can help. Cheers :confused;...

  1. #1

    Default Dynamic removal of text if field is empty using PHP

    I have a mySQL database which has some fields which may, or may not be empty. I
    wish to display them in the following way using PHP:- Result 1; Result 2;
    Result 3; Result 4 and so on. My question is, if the fields for 'Result 2'
    and 'Result 3' are empty, can I dynamically remove the ';' so that my results
    read:- Result 1; Result4 instead of the results I am currently getting:-
    Result 1; ; ; Result 4 I would appreciate any help on this one, as I can't
    seem to find anything which can help. Cheers :confused;

    cp:fusion Guest

  2. #2

    Default Re: Dynamic removal of text if field is empty using PHP

    cp:fusion wrote:
    > My question is, if the fields for 'Result 2'
    > and 'Result 3' are empty, can I dynamically remove the ';' so that my results
    > read:- Result 1; Result4
    if (!empty($variable_that_contains_result)) {
    echo $variable_that_contains_result.'; ';
    }

    The expression !empty() checks that the variable passed to it has a value.

    If the result is empty, nothing will be displayed, thereby omitting the
    redundant semicolon and following space.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  3. #3

    Default Re: Dynamic removal of text if field is empty using PHP

    Hi David, thanks for the reply, I am however struggling with the placement of
    the code in my Dreamweaver generated PHP. Is there any chance you could let me
    know where I should be putting your code in the following example:- Other:
    <?php echo $row_rsCCAPsearch['Orig_Desig']; ?>; <?php echo
    $row_rsCCAPsearch['Equiv_Strains']; ?>; <?php echo
    $row_rsCCAPsearch['Other_Desigs']; ?>; <strong><?php echo
    $row_rsCCAPsearch['Type_Culture']; ?></strong>; <?php echo
    $row_rsCCAPsearch['Extra_Info_1']; ?>; <strong><?php echo
    $row_rsCCAPsearch['Pathogen']; ?></strong>; FORM A MUST ACCOMPANY ORDER<br>
    Many thanks in advance, Craig

    cp:fusion Guest

  4. #4

    Default Re: Dynamic removal of text if field is empty using PHP

    Hi David, thanks for the reply, I am however struggling with the placement of
    the code in my Dreamweaver generated PHP. Is there any chance you could let me
    know where I should be putting your code in the following example:- Other:
    <?php echo $row_rsCCAPsearch['Orig_Desig']; ?>; <?php echo
    $row_rsCCAPsearch['Equiv_Strains']; ?>; <?php echo
    $row_rsCCAPsearch['Other_Desigs']; ?>; <strong><?php echo
    $row_rsCCAPsearch['Type_Culture']; ?></strong>; <?php echo
    $row_rsCCAPsearch['Extra_Info_1']; ?>; <strong><?php echo
    $row_rsCCAPsearch['Pathogen']; ?></strong>; FORM A MUST ACCOMPANY ORDER<br>
    Many thanks in advance, Craig

    cp:fusion Guest

  5. #5

    Default Re: Dynamic removal of text if field is empty using PHP

    cp:fusion wrote:
    > Is there any chance you could let me
    > know where I should be putting your code in the following example:- Other:
    > <?php echo $row_rsCCAPsearch['Orig_Desig']; ?>; <?php echo
    > $row_rsCCAPsearch['Equiv_Strains']; ?>;
    <?php if (!empty($row_rsCCAPsearch['Orig_Desig']))
    echo $row_rsCCAPsearch['Orig_Desig'].'; ';
    if (!empty($row_rsCCAPsearch['Equiv_Strains']))
    echo $row_rsCCAPsearch['Equiv_Strains'].'; ';

    and so on.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  6. #6

    Default Re: Dynamic removal of text if field is empty using PHP

    Thanks very much for your help David, you are a star!

    Craig
    cp:fusion Guest

  7. #7

    Default Re: Dynamic removal of text if field is empty using PHP

    .oO(David Powers)
    >cp:fusion wrote:
    >> Is there any chance you could let me
    >> know where I should be putting your code in the following example:- Other:
    >> <?php echo $row_rsCCAPsearch['Orig_Desig']; ?>; <?php echo
    >> $row_rsCCAPsearch['Equiv_Strains']; ?>;
    >
    ><?php if (!empty($row_rsCCAPsearch['Orig_Desig']))
    > echo $row_rsCCAPsearch['Orig_Desig'].'; ';
    >if (!empty($row_rsCCAPsearch['Equiv_Strains']))
    > echo $row_rsCCAPsearch['Equiv_Strains'].'; ';
    It would probably be easier to loop through the record set ...

    Micha
    Michael Fesser Guest

  8. #8

    Default Re: Dynamic removal of text if field is empty using PHP

    Michael Fesser wrote:
    > It would probably be easier to loop through the record set ...
    I agree, but the original poster wanted to adapt DW-generated code, and
    had difficulty in understanding how to apply !empty(). One step at a time...

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

Similar Threads

  1. #39134 [NEW]: PHP + FreeTDS 0.64 crashes when TEXT field with empty string encountered
    By jr-phpbugs at cedric dot unob dot cz in forum PHP Bugs
    Replies: 6
    Last Post: November 1st, 09:49 AM
  2. File Size From Dynamic Link & If Field is Empty
    By acidrain9 in forum Dreamweaver AppDev
    Replies: 0
    Last Post: May 6th, 04:34 PM
  3. load external text to dynamic text field in levels
    By GaiHo in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 10th, 01:29 AM
  4. How to center text in dynamic HTML text field ???
    By AmnISaid webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: January 20th, 03:01 PM
  5. SQL - Updating Empty Text Field is enterring -1
    By Aaron Bertrand - MVP in forum ASP Database
    Replies: 1
    Last Post: June 26th, 10:28 PM

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