This topic is locked

str_replace doesn't work with numeric values

4/12/2017 6:03:40 AM
PHPRunner General questions
M
mhollibush author

I have a table that stores the data in a numeric value.

using the following:

$value = str_replace(",","
",$value);
It will not put a
between the values on the view page
If I switch the values to characters instead numeric, the
works?
example:

typefield data - 1,2,3 ( ID ) table column set to "varchar"

this will not put a
between the results in the view page

if I change it

word,word,word
the
works?
Any ideas

H
Hertz2P 4/12/2017



I have a table that stores the data in a numeric value.

using the following:

$value = str_replace(",","
",$value);
It will not put a
between the values on the view page
If I switch the values to characters instead numeric, the
works?
example:

typefield data - 1,2,3 ( ID ) table column set to "varchar"

this will not put a
between the results in the view page

if I change it

word,word,word
the
works?
Any ideas


Try without the quotes, numbers typically don't need them in a custom view.

M
mhollibush author 4/13/2017



Try without the quotes, numbers typically don't need them in a custom view.


I am confused on what you mean by try it without quotes... where?

M
mhollibush author 4/14/2017



I am confused on what you mean by try it without quotes... where?


I have tried to take the quoted out and the script errors -

I am confused on why this works when there are words in the field, but it won't work with numeric values -

Y
YCH 4/16/2017



I have tried to take the quoted out and the script errors -

I am confused on why this works when there are words in the field, but it won't work with numeric values -


Not sure if this works.
Convert $value to string first with strval ($value).

$value = str_replace(",","
", strval($value));
Not tested.

M
mhollibush author 4/18/2017

$value = str_replace(",","
", strval($value));
This did not work either.... This is very confusing to me.
Anyone have any other suggestions?

Y
YCH 4/18/2017



$value = str_replace(",","
", strval($value));
This did not work either.... This is very confusing to me.
Anyone have any other suggestions?


Trying to help : you could try single quotes instead of double quotes:
$value = '1,2,3'; // (mind the single quotes here!)

$value = str_replace(',','
', $value); // (mind the single quotes here!)
versus
$value = "1,2,3"; // (mind the double quotes here!)

$value = str_replace(",", "
", $value); // (mind the double quotes here!)
Any of these working ?
Edited --> or finally
$value = '1,2,3';

$search = ',';

$replace = '
';
$value = str_replace( $search, $replace, $value) ;

M
mhollibush author 4/18/2017



Trying to help : you could try single quotes instead of double quotes:
$value = '1,2,3'; // (mind the single quotes here!)

$value = str_replace(',','
', $value); // (mind the single quotes here!)
versus
$value = "1,2,3"; // (mind the double quotes here!)

$value = str_replace(",", "
", $value); // (mind the double quotes here!)
Any of these working ?
Edited --> or finally
$value = '1,2,3';

$search = ',';

$replace = '
';
$value = str_replace( $search, $replace, $value) ;


$value = '1,2,3';

$search = ',';

$replace = '
';
$value = str_replace( $search, $replace, $value) ;
This does the
but it displays the actual numbers in the single quote '1,2,3'

somehow the $value must use the data in the field.

The major issue with this is that the field is the IDs of multiple people ( numbers will change depending on the selection in the Add / Edit pages )
the other options you posted will not put the
in the display
I appreciate your help

I know there is a way to do this, just can't figure it out

Admin 4/18/2017

Function str_replace, of course, works the same way with strings and numbers but there is something else involved. I assume that this field is a multi-select lookup wizard and PHPRunner treats those fields differently depending on how they setup. If Link Field and Display Field are different 'View as' Custom will be executed multiple times, once for each comma separated value. I won't be executed for the whole string like 1,4,6. This means you won't be able to replace commas with
using 'View as' Custom.
Luckily there is a simple workaround, you just need to move your code to another event. On the List page you can use BeforeRecordProcessed event:

https://xlinesoft.com/phprunner/docs/before_record_processed.htm

M
mhollibush author 4/18/2017



Function str_replace, of course, works the same way with strings and numbers but there is something else involved. I assume that this field is a multi-select lookup wizard and PHPRunner treats those fields differently depending on how they setup. If Link Field and Display Field are different 'View as' Custom will be executed multiple times, once for each comma separated value. I won't be executed for the whole string like 1,4,6. This means you won't be able to replace commas with
using 'View as' Custom.
Luckily there is a simple workaround, you just need to move your code to another event. On the List page you can use BeforeRecordProcessed event:

https://xlinesoft.com/phprunner/docs/before_record_processed.htm


I need this on this view page.
On the view page there are two fields ( judges and reps ) that display the results from the multi-select of each field.

The data is stored as the personID but is viewed as the fullname.
the reason I need it stored as a ID is that I want to be able to do a custom view that will link the personID to the view page of that person.
maybe there is a work around I am not finding to solve this