Jump to content

Recommended Posts

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>';
}
}

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.

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!

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.