Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-10-12, 11:30 AM
Junior Member
 
Join Date: Sep 2006
Location: Mansfield - UK
Posts: 19
Midnight is on a distinguished road
Default Need help changing numbers to text in php

Basically I have an account status table in the database but the status is 1, 2, 3, 4, 5 etc

I want to be able to change this status in php so that 1 = Admin, 2 = Banned and so on.

What would be the correct format for doing this? If it is possible.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2006-10-12, 12:52 PM
Senior Member
 
Join Date: Jul 2006
Location: Prague, Czech Republic
Posts: 193
vladimir_cz is on a distinguished road
Send a message via ICQ to vladimir_cz Send a message via MSN to vladimir_cz Send a message via Yahoo to vladimir_cz Send a message via Skype™ to vladimir_cz
Default

just small example:
PHP Code:
$text = array(1=>'admin',2=>'user',3=>'stupid user');
$number 3;
if (isset(
$text[$number]))
   echo 
$text['number'];
else 
   die (
'unknown role!'); 
__________________
Thank you. Vladimir, Czech Republic.
http://www.smartwebco.com/
I'm looking for job.
Reply With Quote
  #3 (permalink)  
Old 2006-10-12, 01:07 PM
Junior Member
 
Join Date: Sep 2006
Location: Mansfield - UK
Posts: 19
Midnight is on a distinguished road
Default

Ok so this is the part of the code that collects the data from the table...

<tr>
<td height="20" bgcolor="#003366">&nbsp;Account Status:</td><td bgcolor="#222222">&nbsp;<?=$user[status]?></td>
</tr>

Would you be able to add the format for me and post it back please?

Status 0 = Banned, 1 = Admin, 2 = Supporter, 3 = Normal, 5 = Moderator

Thank you
Reply With Quote
  #4 (permalink)  
Old 2006-10-12, 02:34 PM
Senior Member
 
Join Date: Jul 2006
Location: Prague, Czech Republic
Posts: 193
vladimir_cz is on a distinguished road
Send a message via ICQ to vladimir_cz Send a message via MSN to vladimir_cz Send a message via Yahoo to vladimir_cz Send a message via Skype™ to vladimir_cz
Default

if $user['status'] present number just make something like:
PHP Code:
<?php

$status 
= array(0=>'Banned'=> 'Admin'=> 'Supporter'=> 'Normal'=> 'Moderator');
?>
and, later in code:
HTML Code:
<td bgcolor="#222222">&nbsp;<?=$status[$user['status']]?></td>
__________________
Thank you. Vladimir, Czech Republic.
http://www.smartwebco.com/
I'm looking for job.
Reply With Quote
  #5 (permalink)  
Old 2006-10-12, 02:38 PM
Junior Member
 
Join Date: Sep 2006
Location: Mansfield - UK
Posts: 19
Midnight is on a distinguished road
Default

Thanks for your reply, I will try it out later and let you know if it works
Reply With Quote
  #6 (permalink)  
Old 2006-10-12, 02:43 PM
Senior Member
 
Join Date: Jul 2006
Location: Prague, Czech Republic
Posts: 193
vladimir_cz is on a distinguished road
Send a message via ICQ to vladimir_cz Send a message via MSN to vladimir_cz Send a message via Yahoo to vladimir_cz Send a message via Skype™ to vladimir_cz
Default

good luck
__________________
Thank you. Vladimir, Czech Republic.
http://www.smartwebco.com/
I'm looking for job.
Reply With Quote
  #7 (permalink)  
Old 2006-10-12, 05:27 PM
Junior Member
 
Join Date: Sep 2006
Location: Mansfield - UK
Posts: 19
Midnight is on a distinguished road
Default

That worked spot on, Thanks for that
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:49 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.