Web site domain - duplication. In other words, if you have a
duplication. In other words, if you have a row with good_id=3 and bad_id=7, then good_id=7 and bad_id=3 must be considered a duplicate. There is no way to prevent that in MySQL using primary keys, so you must take care of that contingency in your code. You do that in a couple of places. In this instance, you are combining two queries in one. The first one grabs all instances of each character where the character s ID is in the good_id field and his enemies IDs are in the bad_id field. The second part of the ON statement reverses that, and pulls all instances of each character where the character s ID is in the bad_id field and his enemies IDs are in the good_id field. This does not prevent reverse duplication (that is handled elsewhere), but it does make sure you have grabbed every possible link to a character s enemy. This code is virtually identical to the multidimensional powers array. This time, you are creating a multidimensional array of each character and that character s enemies. You then implode the enemies list and store it in the $enemies array, using the character s ID as the array index. $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $e[$row[ id ]][] = $row[ alias ]; } foreach ($e as $key => $value) { $enemies[$key] = implode( , , $value); } } You are going to build a table of characters in a moment. In case there are no characters to display (as when you first tested your charlist.php page), you want to display a No characters message. This code builds the $table variable (even though it doesn t contain an actual table) using a
| No characters . currently exist. |
?> Next is another simple SQL SELECT, pulling the appropriate data: character s id, alias, real name, alignment, and address info. Note the $order array. You set that value at the beginning of this page, using the $_GET value o in the URL. This is where it s used to sort the characters. $sql = SELECT id, alias, real_name AS name, align . FROM char_main ORDER BY . $order[$ord]; $result = mysql_query($sql) or die(mysql_error()); You are now building up the table of characters, as long as you returned at least one record from the database. Note the first three columns links. They refer back to this same page, adding the ?o=x parameter. This will re-sort the data and display it sorted on the column the user clicked. if (mysql_num_rows($result) > 0) { $table =