Hi this is going to be quite a complex question to understand so ill try to explain this as thoroughly as possible:
First off, my site is a Final Fantasy site and this problem involves complex tables with vast amount of information. I have information stored in my database on 5 different tables all with a key "id" which is used join all the tables together with their corresponding information.
Now i have a file called bestiary_table.php which stores the template for the html table which is quite complex. The information inside the tables all come from the database tables.
Now i have another filed called bestiary_display.php which is used to connect to the database and actually store the information inside the tables as well as display the tables corresponding to the database information. Here is the code:
<?php
//just arrays of information that will be included in the HTML table bestiary_table.php
$statistics = array( "HP", "MP", "AP", "Gil" );
$attributes = array( "Strength", "Defense", "Magic", "Mag Def", "Aglility", "Luck", "Evasion", "Accuracy" );
$status_effects1 = array( "Sleep", "Silence", "Darkness", "Petrify", "Slow", "Zombie", "Power Br", "Magic Br" );
$status_effects2 = array( "Armor Br", "Mental Br", "Threaten", "Poison", "Death", "Provoke", "Doom", "Null Spells" );
$status_effects3 = array( "Shell", "Protect", "Reflect", "Haste", "Regen", "Distiller", "Sensor", "Scan" );
$status_effects4 = array( "Demi", "Delay", "Eject", "Zanmato", "Fire", "Thunder", "Water", "Ice" );
$others1 = array( "Items Dropped", "Items Stolen" );
$others2 = array( "Drop Ratio", "Ability Slots", "Ability Attached" );
$others3 = array( "Bribe Required", "Enemy Skills Required" );
$others4 = array( "Weapon Abilites", "Armor Abilites", "Location(s) Found" );
$status_effects = array_merge( $status_effects1, $status_effects2, $status_effects3, $status_effects4 );
$others = array_merge( $others1, $others2, $others3, $others4 );
?>
<?php
$link = mysql_connect( localhost, $user, $pass );
mysql_select_db( "$db" );
//names of ALL of the column names for 5 different tables
$all = "statistics.id, type, group_letter, name, image_name, hp, hp_overkill, mp, ap, gil, strength, defense, magic, magic_def, agility, luck, evasion, accuracy, sleep, silence, darkness, petrify, slow, zombie, power_br, magic_br, armor_br, mental_br, threaten, poison, death, provoke, doom, null_spells, shell, protect, reflect, haste, regen, distiller, sensor, scan, demi, delay, eject, zanmato, fire, thunder, water, ice , dropped_normal, dropped_rare, stolen_normal, stolen_rare, drop_ratio, ability_slots, ability_attached, bribe_gil, bribe_item, enemy_skills, armor_abilities, weapon_abilities, location_found";
// this is the actual query which selects everything from the 5 tables and makes sure all the information under the same id go together
$result = mysql_query( "SELECT $all FROM statistics, attributes, status_effects, others
WHERE statistics.id = attributes.id
AND attributes.id = status_effects.id
AND status_effects.id = others.id
AND others.id = statistics.id" ) or die ( "Query Failed" );
// this just loops information in the database and puts in all the information into the HTML file that is included
while ( $bestiary = mysql_fetch_array( $result, MYSQL_NUM ) ) {
include ( "bestiary_table.php" );
}
?>
Now with this i was successfully able to view all of my 5 HTML tables (lets say i have 5 different id's filled with information) that have gotten information from the database.
Now here's the part i need help on. I want to have some sorting to this so it is more user compatible and whatnot.
I want to have 3 sorting functions which we'll call: sort, order and by
1) SORT will be used for sorting the HTML tables and the data into different group letters ( A to Z ). For example, lets say i have:
ID 1 - group_letter: A, Name: Apple
ID 2 - group_letter: A, Name: Adam
ID 3 - group_letter: B, Name: Bobby
ID 4 - group_letter: P, Name: PHP
ID 5 - group_letter: Z, Name: Zebra
lets say SORT=A, then only the group letters with A will be displayed showing Apple, Adam's tables with information. If SORT=B, Bobby's table is displayed only and so forth. This is the SORT function.
2) BY will be used for sorting the HTML tables by various information in the tables such as HP, MP, AP, GIL for example as it is in my database. For example, lets say we had more information to the example started in the SORT explanation. So we now had:
ID 1 - group_letter: A, Name: Apple, HP: 1, MP: 50
ID 2 - group_letter: A, Name: Adam, HP: 2, MP: 60
ID 3 - group_letter: B, Name: Bobby, HP: 3, MP: 70
ID 4 - group_letter: P, Name: PHP, HP: 4, MP: 80
ID 5 - group_letter: Z, Name: Zebra, HP: 5, MP: 90
If i ran BY=HP, then it would display the HP by ASCENDING or DESCENDING order depending on which it was (this will be explained in step 3). But for now lets say we had SORT=A & BY=HP, by descending order, it would display Adam THEN Adam in this case because it is going descending order by HP.
3) ORDER will be used for sorting the HTML tables and the data by ASCENDING or DESCENDING order. This is only to be used to sort whatever is chosen in BY, by Ascending or Descending order. So going back on that example from BY, if it were BY=HP & ORDER=DESC, it would obviously sort everything and display the HTML tables and information by HP DESCENDING order being 5,4,3,2,1 with the corresponding names.
I kno this may be quite difficult to understand and quite complex (for me anyways), but this is the best i can explain this. I also am not skilled enough in Mysql and PHP quite yet to do this myself or figure it out for that matter so that is why im putting this up here. So basically, the URL should look something like this: (I will use capital letters for the sorting part)
mysiteurl/bestiary_display.php?SORT=letter_goes_here(e.g. A,B,C)&BY=whatever_it_should_be_sorted_by(e.g. Hp, Mp, Ap)&ORDER=descending_or_ascending
An example:
mysiteurl/bestiary_display.php?SORT=a&BY=name&ORDER=DESC
This would display on the screen:
All HTML tables with information that has Name letter starting with A (e.g. Adam, Apple), and sorted by Name in Descending Order (e.g. Apple, Adam).
This would be it and whoever can help me... OMG THEY ARE THE KING OF ALL KINGS. ANY if at all help would be totally appreciated and ill be their slave for as long as i live 😉
Thanks alot!
*PS Sorry about the Coding messing up the Tables of this forum post.