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

Load a controller into an other controller in cakephp
Codeigniter + ajax(jQuery) session problem
Confused on the basics of AJAX
netbeans autocompletion when using singleton to retrieve object instead of new operator?
I am having trouble using jquery to submit a form. It was working before;/
Autopruning after a specified amount of row are created?
Facebook Application with PHP running losing session
Condensing multiple else if statements, referencing them from a table?
Resize a photo after being submitted with a form via PHP
PHP, display image with Header()
How can I get a 302 redirection URL's Location header in PHP?
unusual ternary operation
noob: how to show login error message on the same page after php server processes request
PHP Dynamic Count & Limit Menu items
Bing search API. Colon in XML
Is it more efficient to always run a delete query, or to check if that information exists first

Categories

HOME
macos-sierra
shinyapps
barcode-scanner
applescript
hid
websocket
jersey-2.0
portable-class-library
save
graphql-js
telegraf
yeoman-generator-angular
nexus3
nsstring
sap-fiori
responsivevoice
complexity-theory
xbox360
texas-instruments
supervisord
google-cloud-logging
rest-assured
xsl-fo
infrared
adminlte
akka-persistence
hdl
bosun
conda
amazon-sns
plyr
webviewclient
sap-lumira
laravel-4.2
basic-authentication
openbr
nsmutablearray
listjs
devtools
best-buy-api
ejml
hypothesis-test
oracle-bmcs
liteide
directwrite
image-registration
xcglogger
simple-schema
connect-direct
prefetch
nitrousio
haraka
yui3
streamwriter
gcloud-node
jenkins-workflow
nsdata
codecharge
gravatar
largenumber
enaml
swagger-maven-plugin
unidata
deque
incron
baseadapter
jolie
operands
microsoft-expression-web
comctl32
password-recovery
rubber
back
stripe.net
flipboard
colon
notifyjs
microformats
chartfx
delphi-xe4
kobold2d
series-40
algol68
acpi
wiktionary
qtextbrowser
filelock
space-partitioning
css-friendly
solandra
ios-4.2
asdoc
bucket

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App