Forum Moderators: coopster

Message Too Old, No Replies

Using Playton replacing 0 with none in php

         

Topshed71

8:01 am on Jun 19, 2011 (gmt 0)

10+ Year Member



Hi Everyone

I am using the Playton php scripts and I would like to replace zero's with a blank space on the screen

Each field has it' own piece of code and up to 4 of them are numeric which contain a fairly large percentage of Zero's. below is the code for just one field


$opts['fdd']['Other_no'] = array(
'default' => '',
'help|ACP' => 'Limit 5 characters',
'input' => '',
'maxlen' => 5,
'name' => 'S.R-No',
'options' => 'ADCVFL',
'select' => 'T',
'size' => 5,
'sqlw' => 'TRIM("$val_as")',
'sort' => true
);


I suspect I need to create a var and use it when the result is '0' but I cannot get my head around it
Any help welcome
Thanks Topshed

coopster

12:46 pm on Jun 20, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not seeing any zeros in that array? Can you explain what you have and what you would like to see? For example, if it were this array and you are saying that "the size field contains a zero for the value. I want it to display a blank space instead in the HTML output."

rocknbil

3:26 pm on Jun 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo ($opts['fdd']['Other_no']['default']==0)?'':$opts['fdd']['Other_no']['default'];

I probably have the array indexing wrong, but you get the idea - use a ternary wherever you need it.

Topshed71

5:29 am on Jun 21, 2011 (gmt 0)

10+ Year Member



Thanks for your interest Coopster

You have it in one...
The values can be any number between 0 and 92300 in that array and many of the values are zeros
I want to change the output to the screen to a blank when they occur
The Field itself Must be an Integer so I recon it has to be done in PHP ?
I mean I feel this...
92200
92201
0
0
0
92207
0
0
Looks a bit Naff

Regards Topshed

Topshed71

5:36 am on Jun 21, 2011 (gmt 0)

10+ Year Member



Hi rocknbil, thanks for the reply,

I am a bit of a duffer when it comes to PHP and my logic falls over once I go past ASP
I think I should use something like this

IF echo ($opts['fdd']['Other_no'] ==0)?'':$opts['fdd']['Other_no'][' '];

or a stored var containing " "
Possibly totally wrong but my head just wont clear on this

Regards
topshed

coopster

2:24 pm on Jun 21, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



While you are iterating over the array you can use the ternary operator to determine if the value is zero. If so, print out a blank, otherwise use the value. The PHP online manual has examples that explain it a bit better.
[php.net...]

rocknbil

4:13 pm on Jun 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No IF . . . the ternary is short circuit evaluation - this

echo ($opts['fdd']['Other_no'] ==0)?'':$opts['fdd']['Other_no'][' '];

is equivalent to this

if ($opts['fdd']['Other_no'] ==0) {
echo '';
}
else{ echo $opts['fdd']['Other_no'][' ']; }

Topshed71

2:39 am on Jul 2, 2011 (gmt 0)

10+ Year Member



Well I have fought with this for a while and I still cannot get my head in the right place

My latest code to acheive my goal follows

$opts['fdd']['other_no'] ==0 ?'':$opts['fdd']['br_no'][' '];
$opts['fdd']['other_no'] = array(
'css' => array('postfix' => 'tac'),
'default' => '',
'help|ACP' => 'Limit 5 digits',
'input' => '',
'maxlen' => 6,
'name' => 'Br_No',
'options' => 'ACPVDFL',
'select' => 'T',
'size' => 5,
'sqlw' => 'TRIM("$val_as")',
'sort' => true
);


Which does not work !
I also have tried

$opts['fdd']['other_no'] ==0 ?'':$opts['fdd']['other_no'][' '] = array(/$opts['fdd']['other_no'] = array(

Which kills the whole column

So more newbie help required please

Roy..

Topshed71

2:42 am on Jul 2, 2011 (gmt 0)

10+ Year Member



Oops the top line of code should read

$opts['fdd']['other_no'] ==0 ?'':$opts['fdd']['other_no'][' '];

Sorry