Dynamic removal of text if field is empty using PHP

Ask a Question related to Dreamweaver AppDev, Design and Development.

  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. Similar Questions and Discussions

    1. #39134 [NEW]: PHP + FreeTDS 0.64 crashes when TEXT field with empty string encountered
      From: jr-phpbugs at cedric dot unob dot cz Operating system: linux (irrelevant) PHP version: 4.4.4 PHP Bug Type: MSSQL...
    2. File Size From Dynamic Link & If Field is Empty
      1. i have an access database set up with a pdf file link in one field on the actual page the user has the option to view the pdf or save it. ...
    3. load external text to dynamic text field in levels
      Dear Sir I found the Tech Noe Index #16238 is useful in creating dynamically loaded text from external text file. However, the method mentioned...
    4. Dynamic text in smooth scrolling text field - help
      here's links to the files. http://www.anicespot.com/test/ http://www.anicespot.com/test/easing_textScroller-01.html...
    5. SQL - Updating Empty Text Field is enterring -1
      > "Update set userid = '" & REquest.form("userid") & Response.write this to the screen, instead of executing it, and examine the result.
  3. #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

  4. #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

  5. #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

  6. #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

  7. #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

  8. #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

  9. #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

Posting Permissions

  • You may not post new threads
  • You may 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