ok, i started with a javascript problem, its resolution creates a php issue for me
heres what i need to do
i have a database, table looks like this
[code=php]
+———————–+
| ID | RACE | CLASS |
+—-+——–+———+
| 1 | Elf | Hunter |
| 2 | Dwarf | Mage |
| 3 | Elf | Warrior |
| 4 | Human | Druid |
| 5 | Ogre | Mage |
| 6 | Dwarf | Druid |
| 7 | Elf | Druid |
| 8 | Human | Hunter |
| 9 | Human | Mage |
| 10 | Ogre | Druid |
| 11 | Dwarf | Hunter |
| 12 | Ogre | Hunter |
+———————–+
i need to pull all this data, and format it like so
[code=php]
/*************************************************
* this will actually fit into a javascript code *
* this is the formatting i need, notice the *
* comma (or lack of) after the () *
*************************************************/
class = new Array(
new Array( // Dwarves
new Array(“Druid”, “Druid”), // comma
new Array(“Hunter”, “Hunter”), // comma
new Array(“Mage”, “Mage”) // no comma
),
// Duplicated to show the Option Value and the Option Choice
new Array( // Elves
new Array(“Druid”, “Druid”),
new Array(“Hunter”, “Hunter”),
new Array(“Warrior”, “Warrior”)
),
new Array( // Humans
new Array(“Druid”, “Druid”),
new Array(“Hunter”, “Hunter”),
new Array(“Mage”, “Mage”)
),
new Array( // Ogres
new Array(“Druid”, “Druid”),
new Array(“Hunter”, “Hunter”),
new Array(“Mage”, “Mage”)
)
);
As you can see, I need to sort each array alphabetically, and each nested array should be alphabetical too
i dont need the comments, that is just to show you where the info was pulled from
im sure it involves nested while loops, but not sure how to get it formatted properly, and with comma’s where necessary, and missing where not
its probably simpeler than i am thinking, but who knows, i like to make my life difficult
make sence?
it will be used in this script
[code=php]<html>
<HEAD>
<title>-</title>
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
classes = new Array(
new Array(
new Array(“Druid”, “Druid”),
new Array(“Hunter”, “Hunter”),
new Array(“Mage”, “Mage”)
),
new Array(
new Array(“Druid”, “Druid”),
new Array(“Hunter”, “Hunter”),
new Array(“Warrior”, “Warrior”)
),
new Array(
new Array(“Druid”, “Druid”),
new Array(“Hunter”, “Hunter”),
new Array(“Mage”, “Mage”)
),
new Array(
new Array(“Druid”, “Druid”),
new Array(“Hunter”, “Hunter”),
new Array(“Mage”, “Mage”)
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i–) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
} else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End –>
</script>
</HEAD>
<BODY>
<FORM NAME=”main” action=”multidrop.html”>
<SELECT NAME=”Race” onChange=”fillSelectFromArray(this.form.Classes, ((this.selectedIndex == -1) ? null : classes[this.selectedIndex-1]));”>
<OPTION VALUE=”-1″>Select Race</option>
<OPTION VALUE=”Dwarf”>Dwarf</option>
<OPTION VALUE=”Elf”>Elf</option>
<OPTION VALUE=”Human”>Human</option>
<OPTION VALUE=”Ogre”>Ogre</option>
</SELECT>
<BR />
<SELECT NAME=”Classes”>
<OPTION>Select Class</OPTION>
</SELECT>
<input type=”submit” value=”ok” />
</FORM>
</body>
</html>