Jump to content

[SOLVED] Tool Tip Snafu - Items display as 'numbers' instead of 'descriptions'


Chezshire

Recommended Posts

I've built a database which people use to record data, the data in the 'Hair Color' and 'Eye Color' displays as numbers, rather then as the array selections. How would i translate the numbers back to their corresponding colors from the function array? Help please!

<?php

if (!function_exists("microtime_float")) {
include ("functions.php");
approveVars(array("tooltip_id"));
} // end if being called externally

$gamedateFile = "$basefile/gamedate/gamedate.txt";
$tempy = file($gamedateFile);
$gameDate = trim($tempy[0]);
$realDate = trim($tempy[1]);

echo "<p class='fineprint'>";

$thumbFile = "$basefile/cerebra/images/$tooltip_id-.jpg";
$mainFile = "$basefile/cerebra/images/$tooltip_id.jpg";

if (file_exists($thumbFile)) {
$size = getimagesize($thumbFile);
echo "<img src='/cerebra/images/$tooltip_id-.jpg' width='60' height='75' align='right' style='margin:4; border:solid 1px #415582;'>";
} else if (file_exists($mainFile)) {
$size = getimagesize($mainFile);
$height = 60 * $size[1] / $size[0];
echo "<img src='/resizer.php?img=cerebra/images/$tooltip_id.jpg&width=60' height='$height' width='60' align='right' style='margin:4; border:solid 1px #415582;'>";
} // end image search

$tt_details = readDatabase("SELECT *,  IFNULL(FLOOR((TO_DAYS('$gameDate') + FLOOR((TO_DAYS(NOW()) - TO_DAYS('$realDate')) / 14) - TO_DAYS(dateofbirth)) / 365.25) ,0) AS age from cerebra WHERE id = $tooltip_id");

echo "<b style='color: #415582;'>" . $tt_details["codename"] . "</b><br>\n";
echo  $tt_details["name"]. "</p>\n" ;

echo "<p class='fineprint'><b>AGE:</b> " . $tt_details["age"] . "<br>\n";

echo "<b>HEIGHT:</b> " . $tt_details["height1"] . "&#39; " 
                       . $tt_details["height2"] . "&#34;<br>\n";

echo "<b>WEIGHT:</b> " . $tt_details["weight1"] . "" 
                       . $tt_details["weight2"] . ""
                       . $tt_details["weight3"] . "<br>\n";


echo "<b>EYES:</b> " . $tt_details["eyes"] . "<br>\n";
echo "<b>HAIR: </b>" . $tt_details["hair"] . "<br>\n";


echo "<b>DEMEANOR:</b> " . $tt_details["demeanor"] . "<br>\n";
echo "<b>NATURE:</b> " . $tt_details["nature"] . "<br>\n";
echo "<b>CLASS:</b> " .$classificationName[$tt_details["classificationsDB"]] . "</p>\n";

?>

 

 

 

Function 1: Eye Color

$eyeColor = array("None", "Amber", "Black", "Blue", "Brown", "Gold", "Green", "Grey", "Hazel", "Lavender", "Orange", "Pink", "Purple", "Red", "Silver", "Violet", "White", "Other", "Unknown");

 

Function 2: Hair color

$hairColor = array("None", "Auburn", "Black", "Blue", "Blond", "Brown", "Gold", "Green", "Grey", "Lavender", "Orange", "Pink", "Purple", "Red", "Silver", "White", "Bald", "Shaven", "Other", "Unknown");

 

What do you mean by "displays as numbers"? Are you storing the numbers as the corresponding array key? If so it should be easy:

 

<?php
$eyeColor = array("None", "Amber", "Black", "Blue", "Brown", "Gold", "Green", "Grey", "Hazel", "Lavender", "Orange", "Pink", "Purple", "Red", "Silver", "Violet", "White", "Other", "Unknown");
$key = 3; //got from the database
echo $eyeColor[$key]; //will print "Blue"
?>

Hey GuiltyGear,

  thanks for replying, and in answer to what you ask, yes, i did store the info as numbers of the corresponding array rather then as the words themselves. I don't want to go redo the enter code as then i'd have to re-enter the data of two hundred characters to get the tooltip to display the mouseover info correctly (i'm trying to work smarter, not harder). I tried applying your code suggestion, but i'm not sure where i would slug it in. Below is what I tried and it disabled the mouseover completely. I'm not sure how to apply this key. (i'm a newb and i stumble through this stuff at best).

 

Thanks for any help GuiltyGear!

 

What i tried (and didn't work)

<?php

if (!function_exists("microtime_float")) {
include ("functions.php");
approveVars(array("tooltip_id"));
} // end if being called externally

$gamedateFile = "$basefile/gamedate/gamedate.txt";
$tempy = file($gamedateFile);
$gameDate = trim($tempy[0]);
$realDate = trim($tempy[1]);

echo "<p class='fineprint'>";

$thumbFile = "$basefile/cerebra/images/$tooltip_id-.jpg";
$mainFile = "$basefile/cerebra/images/$tooltip_id.jpg";

if (file_exists($thumbFile)) {
$size = getimagesize($thumbFile);
echo "<img src='/cerebra/images/$tooltip_id-.jpg' width='60' height='75' align='right' style='margin:4; border:solid 1px #415582;'>";
} else if (file_exists($mainFile)) {
$size = getimagesize($mainFile);
$height = 60 * $size[1] / $size[0];
echo "<img src='/resizer.php?img=cerebra/images/$tooltip_id.jpg&width=60' height='$height' width='60' align='right' style='margin:4; border:solid 1px #415582;'>";
} // end image search

$tt_details = readDatabase("SELECT *,  IFNULL(FLOOR((TO_DAYS('$gameDate') + FLOOR((TO_DAYS(NOW()) - TO_DAYS('$realDate')) / 14) - TO_DAYS(dateofbirth)) / 365.25) ,0) AS age from cerebra WHERE id = $tooltip_id");

echo "<b style='color: #415582;'>" . $tt_details["codename"] . "</b><br>\n";
echo  $tt_details["name"]. "</p>\n" ;

echo "<p class='fineprint'><b>AGE:</b> " . $tt_details["age"] . "<br>\n";

echo "<b>HEIGHT:</b> " . $tt_details["height1"] . "&#39; " 
                       . $tt_details["height2"] . "&#34;<br>\n";

echo "<b>WEIGHT:</b> " . $tt_details["weight1"] . "" 
                       . $tt_details["weight2"] . ""
                       . $tt_details["weight3"] . "<br>\n";


$eyeColor = array("None", "Amber", "Black", "Blue", "Brown", "Gold", "Green", "Grey", "Hazel", "Lavender", "Orange", "Pink", "Purple", "Red", "Silver", "Violet", "White", "Other", "Unknown");
$key = 3; //got from the database

echo $eyeColor[$key]; //will print "Blue"

echo "<b>EYES:</b> " . $tt_details["eyes"] . "<br>\n";

echo "<b>HAIR: </b>" . $tt_details["hair"] . "<br>\n";


echo "<b>DEMEANOR:</b> " . $tt_details["demeanor"] . "<br>\n";
echo "<b>NATURE:</b> " . $tt_details["nature"] . "<br>\n";
echo "<b>CLASS:</b> " .$classificationName[$tt_details["classificationsDB"]] . "</p>\n";

?>

 

From what i can guess:

 

<?php
$colors = array("None", "Amber", "Black", "Blue", "Brown", "Gold", "Green", "Grey", "Hazel", "Lavender", "Orange", "Pink", "Purple", "Red", "Silver", "Violet", "White", "Other", "Unknown");
$eyeKey = $tt_details['eyes'];
$hairKey = $tt_details['hair'];
echo "<b>EYES:</b> " . $colors[$eyeKey] . "<br>\n";
echo "<b>HAIR: </b>" . $colors[$hairKey] . "<br>\n";
?>

 

That way it should work, but as i said before, only if you have stored in the db the array keys (ie, 1 or 4 or 0). Otherwise, if the stored values in the db are just some random numbers, you'll have to re-enter them to use the appropriate keys. Give it a try, hope it works.

Hmmmms and Arrrrghs (but not like a pirate, more like your dad when the car over heats and he's stuck by the road and is mostly just pretending to understand ;)

 

I tried apply the logic you sent, and it beat my little forum up completely. No messages appeared save those that came in AFTER the new logic was applied to the tool tip. I thought that perhaps the problem was that the bracketed keys needed quote marks so i added them as shown below:

 

From the code you suggested:

echo "<b>EYES:</b> " . $colors[$eyeKey] . "<br>\n";

echo "<b>HAIR: </b>" . $colors[$hairKey] . "<br>\n";

 

Added quote marks inside the brackets:

echo "<b>EYES:</b> " . $colors["$eyeKey"] . "<br>\n";

echo "<b>HAIR: </b>" . $colors["$hairKey"] . "<br>\n";

 

It still didn't work :(

Any more thoughts or observations?

 

Below is the full code as i tried to implement it (I shall google more and hem and haw at my overheating engine-i mean website ;)

<?php

if (!function_exists("microtime_float")) {
include ("functions.php");
approveVars(array("tooltip_id"));
} // end if being called externally

$gamedateFile = "$basefile/gamedate/gamedate.txt";
$tempy = file($gamedateFile);
$gameDate = trim($tempy[0]);
$realDate = trim($tempy[1]);

$colors = array("None", "Amber", "Black", "Blue", "Brown", "Gold", "Green", "Grey", "Hazel", "Lavender", "Orange", "Pink", "Purple", "Red", "Silver", "Violet", "White", "Other", "Unknown");
$eyeKey = $tt_details['eyes'];
$hairKey = $tt_details['hair'];


echo "<p class='fineprint'>";

$thumbFile = "$basefile/cerebra/images/$tooltip_id-.jpg";
$mainFile = "$basefile/cerebra/images/$tooltip_id.jpg";

if (file_exists($thumbFile)) {
$size = getimagesize($thumbFile);
echo "<img src='/cerebra/images/$tooltip_id-.jpg' width='60' height='75' align='right' style='margin:4; border:solid 1px #415582;'>";
} else if (file_exists($mainFile)) {
$size = getimagesize($mainFile);
$height = 60 * $size[1] / $size[0];
echo "<img src='/resizer.php?img=cerebra/images/$tooltip_id.jpg&width=60' height='$height' width='60' align='right' style='margin:4; border:solid 1px #415582;'>";
} // end image search

$tt_details = readDatabase("SELECT *,  IFNULL(FLOOR((TO_DAYS('$gameDate') + FLOOR((TO_DAYS(NOW()) - TO_DAYS('$realDate')) / 14) - TO_DAYS(dateofbirth)) / 365.25) ,0) AS age from cerebra WHERE id = $tooltip_id");

echo "<b style='color: #415582;'>" . $tt_details["codename"] . "</b><br>\n";
echo  $tt_details["name"]. "</p>\n" ;

echo "<p class='fineprint'><b>AGE:</b> " . $tt_details["age"] . "<br>\n";

echo "<b>HEIGHT:</b> " . $tt_details["height1"] . "&#39; " 
                       . $tt_details["height2"] . "&#34;<br>\n";

echo "<b>WEIGHT:</b> " . $tt_details["weight1"] . "" 
                       . $tt_details["weight2"] . ""
                       . $tt_details["weight3"] . "<br>\n";


echo "<b>EYES:</b> " . $colors["$eyeKey"] . "<br>\n";
echo "<b>HAIR: </b>" . $colors["$hairKey"] . "<br>\n";




echo "<b>DEMEANOR:</b> " . $tt_details["demeanor"] . "<br>\n";
echo "<b>NATURE:</b> " . $tt_details["nature"] . "<br>\n";
echo "<b>CLASS:</b> " .$classificationName[$tt_details["classificationsDB"]] . "</p>\n";

?>

 

 

 

 

SOLVED IT!!!!!

 

I Changed the following code:

.$tt_details["hair"]

 

Like so:

.$hairColor[$tt_details["hair"]]

 

The lesson learned? Behold the power of brackets!

thanks for all the help GuiltyGear! I really doubt i would have figured this out with out your help

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.