How It Works You created two different (Business web site) files

How It Works You created two different files in this exercise, so we re going to take them apart and look at them individually here. charlist.php The charlist.php page has an optional parameter that can be passed: ?o=x, where x is 1, 2, or 3. This code retrieves that variable if it exists, and converts it to the appropriate value if necessary. If some smart-aleck types o=4 in the browser, the code returns 3. If no value or a bad value is passed, it will default to 1. The value is stored in $ord. if (isset($_GET[ o ]) && is_numeric($_GET[ o ])) { $ord = round(min(max($_GET[ o ], 1), 3)); } else { $ord = 1; } $order = array(1 => alias ASC , 2 => name ASC , 3 => align ASC, alias ASC ); This value determines which column the character display will be sorted on: 1 is by alias, 2 is by real name, and 3 is by alignment and then alias. You will use the value $ord as the key to your order array, which will be appended to the appropriate SQL statement later. Make a connection, and choose a database. You know the drill by now. $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die( Could not connect to MySQL database. . mysql_error()); mysql_select_db(SQL_DB, $conn); Ah . . . your first JOIN. This SELECT statement might look confusing to the uninitiated, but it is not that complicated. First, look at the JOIN statements. You are joining three tables, using the char_power_link table to link the char_power table and the char_main table. This is a many-to-many (M:N) relationship. You define how they are joined with the ON statement. As you can see, you are linking up the character table to the link table using the character id, and you re linking the power table to the link table using the power id. With that link established, you can see that you are grabbing the character s ID and the powers assigned to each character. $sql = SELECT c.id, p.power . FROM char_main c . JOIN char_power p . JOIN char_power_link pk . ON c.id = pk.char_id AND p.id = pk.power_id ; $result = mysql_query($sql) or die(mysql_error()); 316 Chapter 10
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply