server side scripting : if null cannot just show nothing ' '

server side scripting : if null cannot just show nothing ' '

fc338339fc338339 Posts: 16Questions: 8Answers: 1

Field::inst( 'tablename.fieldname' )->setFormatter( 'Format::ifEmpty', '' ),

or

Field::inst( 'tablename.fieldname' )->setFormatter( 'Format::ifNull', '' ),

as result it still show 'null'

please help

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @fc338339 ,

    as result it still show 'null'

    Is this in the database, or the table on the client? Looking at the code, it should be setting the value in the database to be an empty string. One point, the manual here only has the fieldname, I'm not sure it needs to be prefixed by tablename. .

    Hope that helps,

    Cheers,

    Colin

  • fc338339fc338339 Posts: 16Questions: 8Answers: 1
    edited August 2019

    This coding is in databases at server-side-processing.php
    which need to include

    include( $_SERVER['DOCUMENT_ROOT']."/modules/Editor-PHP-1.5.3/php/DataTables.php" );

    Field::inst( 'name' )->setFormatter( Format::ifEmpty( null ) ),
    Field::inst( 'age' )->setFormatter( Format::ifEmpty( 0 ) )
    

    above two Format IS NOT what I want,

    I even try below method but still show 'null'

    Field::inst( 'name' )->setFormatter( Format::ifEmpty( ''  ) ),
    Field::inst( 'name' )->setFormatter( Format::ifEmpty( ""  ) ),
    

    I wish DO NOT SHOW ** 'null' or '0'**

    Please do help

    Thanks

  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin

    You don't need a set formatter at all if you just want an empty string to be saved as an empty string (unless you are using an Oracle db or a trigger which will set empty strings to be null).

    Can you have a look in your database directly (using phpMyAdmin, pgAdmin or whatever database tool you use for your db) and let me know if null is what is actually being stored?

    Allan

This discussion has been closed.