artursm15 Posted February 16, 2015 Share Posted February 16, 2015 Hello Guys i would like to get some help . I'm wondering how can i change id what i get from mysql db to a name for example i get id 2000 ,2032,2100,2304 and i would like change them like if get 2000="wordOne" if get 2032="wordten" and so on! My code is here where it gets id from db ! <?php if(!$conn) echo 'Can\'t connect to the database'; else { $raidspawn = mysql_query("SELECT boss_id,respawn_time FROM raidboss_spawnlist ORDER BY respawn_time DESC"); while(list($boss_id,$respawn_time) = mysql_fetch_row($raidspawn)) { $text = '<font color="00FF00">'.$boss_id.'</font>'; $respawn = '<font color="0000FF">spawned</font>'; if($respawn_time > 0) { $respawntime = date('H:i:s',($respawn_time / 1000)); $text = '<font color="FF0000">'.$boss_id.'</font>'; $respawn = '<font color="FF0000">Respawn '.$respawntime.'</font>'; } echo '<tr><td>'.$text.'</td><td>'.$respawn.'</td></tr>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/294639-if-get-id-from-mysql-db-change-id-to-a-word/ Share on other sites More sharing options...
NotionCommotion Posted February 16, 2015 Share Posted February 16, 2015 Not sure I understand the question. What are you attempting to do? 1 Quote Link to comment https://forums.phpfreaks.com/topic/294639-if-get-id-from-mysql-db-change-id-to-a-word/#findComment-1505797 Share on other sites More sharing options...
Tom10 Posted February 16, 2015 Share Posted February 16, 2015 Not sure I understand the question. What are you attempting to do? Me too i'm not quite sure what your asking. Quote Link to comment https://forums.phpfreaks.com/topic/294639-if-get-id-from-mysql-db-change-id-to-a-word/#findComment-1505801 Share on other sites More sharing options...
Ch0cu3r Posted February 16, 2015 Share Posted February 16, 2015 So you want to associate the boss_id with a word? If so you could do something like this // define the words in an array. The boss id will be the key, and assign the word as the value for that key $words = array( 2000 => 'World One', 2032 => 'World Ten', ...etc ); ... while(list($boss_id,$respawn_time) = mysql_fetch_row($raidspawn)) { $text = '<font color="00FF00">'.$words[$boss_id].'</font>'; // use $boss_id as the key for $words array to get the associated word. ... } Alternatively you could have the list of words associated with ids stored in another mysql table and use a join to get the word that matches the boss_id. Quote Link to comment https://forums.phpfreaks.com/topic/294639-if-get-id-from-mysql-db-change-id-to-a-word/#findComment-1505814 Share on other sites More sharing options...
artursm15 Posted February 17, 2015 Author Share Posted February 17, 2015 So you want to associate the boss_id with a word? If so you could do something like this // define the words in an array. The boss id will be the key, and assign the word as the value for that key $words = array( 2000 => 'World One', 2032 => 'World Ten', ...etc ); ... while(list($boss_id,$respawn_time) = mysql_fetch_row($raidspawn)) { $text = '<font color="00FF00">'.$words[$boss_id].'</font>'; // use $boss_id as the key for $words array to get the associated word. ... } Alternatively you could have the list of words associated with ids stored in another mysql table and use a join to get the word that matches the boss_id. Soory for my bad info ! well yes right now this script displays only boss_id wich is 2000,2004,2006 and so on but i would like that thouse ID would be changed to names like 2000 would display name "WordOne" in website! Quote Link to comment https://forums.phpfreaks.com/topic/294639-if-get-id-from-mysql-db-change-id-to-a-word/#findComment-1505885 Share on other sites More sharing options...
maxxd Posted February 17, 2015 Share Posted February 17, 2015 Assuming the boss info is stored in another table in your database, you'll want to join the tables in your query. So, basically, if the table 'raidboss_spawnlist' contains the columns boss_id and respawn_time and table 'boss_information' contains the columns boss_id and boss_name, you'd join the two on the column boss_id (it's a foreign key) like this: SELECT b.boss_name ,a.respawn_time FROM raidboss_spawnlist a LEFT JOIN boss_information b ON a.boss_id = b.boss_id ORDER BY respawn_time DESC Of course, this is all moot if you don't have the boss information set up in a separate table; however, if you don't then you should reconsider your database design. Quote Link to comment https://forums.phpfreaks.com/topic/294639-if-get-id-from-mysql-db-change-id-to-a-word/#findComment-1505892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.