Chezshire Posted August 29, 2008 Share Posted August 29, 2008 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"] . "' " . $tt_details["height2"] . ""<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"); Link to comment https://forums.phpfreaks.com/topic/121937-solved-tool-tip-snafu-items-display-as-numbers-instead-of-descriptions/ Share on other sites More sharing options...
Fadion Posted August 29, 2008 Share Posted August 29, 2008 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" ?> Link to comment https://forums.phpfreaks.com/topic/121937-solved-tool-tip-snafu-items-display-as-numbers-instead-of-descriptions/#findComment-629313 Share on other sites More sharing options...
Chezshire Posted August 30, 2008 Author Share Posted August 30, 2008 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"] . "' " . $tt_details["height2"] . ""<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"; ?> Link to comment https://forums.phpfreaks.com/topic/121937-solved-tool-tip-snafu-items-display-as-numbers-instead-of-descriptions/#findComment-629338 Share on other sites More sharing options...
Fadion Posted August 30, 2008 Share Posted August 30, 2008 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. Link to comment https://forums.phpfreaks.com/topic/121937-solved-tool-tip-snafu-items-display-as-numbers-instead-of-descriptions/#findComment-629348 Share on other sites More sharing options...
Chezshire Posted August 30, 2008 Author Share Posted August 30, 2008 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"] . "' " . $tt_details["height2"] . ""<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"; ?> Link to comment https://forums.phpfreaks.com/topic/121937-solved-tool-tip-snafu-items-display-as-numbers-instead-of-descriptions/#findComment-629368 Share on other sites More sharing options...
Chezshire Posted August 30, 2008 Author Share Posted August 30, 2008 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 Link to comment https://forums.phpfreaks.com/topic/121937-solved-tool-tip-snafu-items-display-as-numbers-instead-of-descriptions/#findComment-629463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.