How Do I Change The Database Values Using Php And Mysql?
I have user table having fields gender and first name like this.. The value stored in the database for gender type is 0 for M(Male) and 1 for F(Female). I am retrieving the details
Solution 1:
SELECT CONCAT(usrFirstname,'',usrSurname) As FullName,
usrNickname AS Nickname,
usrEmail As EmailAddress,
CASE WHEN usrGender = 0
THEN
'M'
ELSE
'F'
END AS Gender,
DATE_FORMAT(usrDOB,'%d%m%y') As DOB,usrBelt AS BeltId
FROM user
if you put this in the query it return M or F
Solution 2:
Add this line, right before you echo out the gender:
$row['Gender'] = $row['Gender'] == 0 ? 'M' : 'F';
Or use macwadu's excellent solution, on editing the query.
Solution 3:
or you can do it on php-side:
<td><?phpecho ($row['Gender'] ? 'F' : 'M') ?></td>
Post a Comment for "How Do I Change The Database Values Using Php And Mysql?"