php


PHP - How can i use str_replace in that situation?


i have a column called Status in my table, and the possible values for this column are 1 or 0, 1 means that the row is activated and 0 means that the row is disabled.
But inside my backoffice, i have one html table to edit all the values inside this table.
To edit the values, the admin just need to select some rows(i'm using checkboxes), and click at the button to edit.
This button will show a new html table , inside this html table, i inserted all the values that i have inside my database table, into textboxes to change and edit.
The problem is that i need to show the current Status column value, example:
The status is activated, the value from status is 1.
The value will appear like this:
To change that, i used str_replace
if ($val['status'] == '1'){
$val['status'] = str_replace("1","Active","1");
}else{
$val['status'] = str_replace("0","Disable","0");
}
But when i submit the str_replace changes the value, and sends to my database Active instead 1, or Disabled instead 0.
I'm using a selectbox to chose if the status must be active or disabled
<select name='u_status[".$val['id']."]' class='txtedit'>
<option value=".$val['status']." style='display:none;'>".$val['status']."</option>
<option value='1'>Active</option>
<option value='0'>Disabled</option>
</select>
Thank you.
Create an array with the statuses:
$status = array(
'Disabled',
'Enabled'
);
Then use $val['status'] as the key to get the value you want from that array:
<option value=".$val['status']." style='display:none;'>".$status[$val['status']]."</option>
Don't use str_replace. This is just a boolean.
$val['status'] = ($val['status'] == '1' ? 'Active' : 'Disabled');
or even:
if ($val['status'] == '1') {
$val['status'] = 'Active';
} else {
$val['status'] = 'Disabled';
}

Related Links

Submit button not working in Wordpress
php push dimensional array
class table inheritance in eloquent orm
Laravel Route get controller's construct without method
Highcharts doesn't show all contents of x-axis
Dynamic table with php pdo and two foreach
PHP color of the first line in a loop
Decrypt Rijndael with Passphrase in PHP
WP-API Get Posts After a Specific Date
How Do i Print last 10 days using php? [closed]
MySQL: Joining table duplicates SUM()
how to manuplate the google api php client
Unable to get cookie in construct function
How to loop through Models find from Where clause?
Trying to keep session with curl login in twitter
Code start and end in specific time

Categories

HOME
rust
openshift
protocol-buffers
command-prompt
visual-studio-2010
dronekit-python
lvm
mosquitto
capistrano
stored-procedures
responsive-design
solution
scrape
heap-dump
google-cloud-logging
uima
varnish-vcl
amazon-mws
maven-surefire-plugin
strophe.js
clipboard
jackrabbit-oak
onchange
oracleforms
sendmessage
boolean-logic
progid
universal
devtools
grails-2.5
strapi
mars-simulator
spring-restcontroller
oauth2-playground
1wire
contactless-smartcard
moinmoin
dredd
xcglogger
degrees
instafeedjs
prefetch
petsc
ternary-operator
jsf-2.3
wininet
callouts
simian
openmrs
ioctl
enunciate
grinder
gdl
deeplink
fanotify
knife
jnlp
postal-code
swagger-maven-plugin
android-handler
google-gdk
wicked-gem
innerhtml
nhibernate-criteria
fat32
jolie
microsoft-expression-web
dnsjava
windows-taskbar
lync-2010
django-sites
cloo
application-server
codahale-metrics
form-for
indesign-server
html-frames
xmlwriter
gprof
smartfox
email-verification
towers-of-hanoi
story
workflow-manager-1.x
sfinae
fitch-proofs
qt-mobility
winsxs
hungarian-notation
fxruby
ning
regioninfo
word-automation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App