Archive for October, 2007

Figure 10-4 6. If you click New Character (Web site layout)

Monday, October 22nd, 2007

Figure 10-4 6. If you click New Character again, you should now see an extra field for Enemies. You can select any previously created character in the database as the current character s enemy. 7. From the home page, click one of your characters names. The Character Editor page loads again, but now the background is green, and the character s data will be automatically entered into the fields (see Figure 10-5). If you look at the URL for this page, you see ?c=x at the end, where x is the character s number. 8. Change some of the data, and click Update Character. You are taken back to the home page, and you should immediately see the results of your changes. In fact, if you selected an enemy for this character, you should see the results change in the enemy s row as well. 314 Chapter 10
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Frontpage web hosting - Figure 10-3 313 Building Databases

Sunday, October 21st, 2007

Figure 10-3 313 Building Databases
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

3. Open your browser, and point it to (Cool web site)

Saturday, October 20th, 2007

3. Open your browser, and point it to the location of charlist.php. This is your Character Database home page. It should look something like Figure 10-2. If the logo is missing, you can download it from the Web site, edit the four pages to eliminate the image, or change it to anything you want. Because you don t currently have any characters to look at, let s move on. Figure 10-2 4. Click the New Character link. A shiny new page appears, ready for your data input (see Figure 10-3). You will notice that the powers you entered are choices in the Powers field. (Relational databases rule!) 5. Enter the appropriate data, and click Create Character. You should be taken to the home page, where you ll now see the character you entered (as in Figure 10-4). 312 Chapter 10
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

> evil Enemies: (Ctrl-click toselect multipleenemies)     

Friday, October 19th, 2007
> good
> evil


Enemies:
(Ctrl-click to
select multiple
enemies)


Character >     

>

Return to Home Page 311 Building Databases
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Web hosting mysql - > Real Name: Lair Location: (address,city, state, zip)

Thursday, October 18th, 2007
>

310 Chapter 10
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

AND c.id = $char ; $result = (Web server application) mysql_query($sql) or

Wednesday, October 17th, 2007

AND c.id = $char ; $result = mysql_query($sql) or die(mysql_error()); $ch = mysql_fetch_array($result); if (is_array($ch)) { $subtype = Update ; $tablebg = #EEFFEE ; $subhead = Edit data for . $ch[ alias ] . and click $subtype Character. ; $sql = SELECT p.id . 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 . WHERE c.id = $char ; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $powers[$row[ id ]] = selected ; } } // get list of character s enemies $sql = SELECT n.id . FROM char_main c . JOIN char_good_bad_link gb . JOIN char_main n . ON (c.id = gb.good_id AND n.id = gb.bad_id) . OR (n.id = gb.good_id AND c.id = gb.bad_id) . WHERE c.id = $char ; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $enemies[$row[ id ]] = selected ; } } } } ?>

Comic Book
Appreciation


309 Building Databases
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

$table); } echo $table; ?> New Character •

Tuesday, October 16th, 2007

$table); } echo $table; ?>
New CharacterEdit Powers 2. In the last file for this chapter, you ll create the ability to add and modify characters. Enter the next block of code and save it as charedit.php: 0) { while ($row = mysql_fetch_array($result)) { $pwrlist[$row[ id ]] = $row[ power ]; } } $sql = SELECT id, alias FROM char_main WHERE id != $char ; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); $charlist[$row[ id ]] = $row[ alias ]; } if ($char != 0 ) { $sql = SELECT c.alias, c.real_name AS name, c.align, . l.lair_addr AS address, z.city, z.state, z.id AS zip . FROM char_main c, char_lair l, char_zipcode z . WHERE z.id = l.zip_id . AND c.lair_id = l.id . 308 Chapter 10
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

$enemies[$key] = implode( , , $value); } } $table (Unlimited web hosting)

Tuesday, October 16th, 2007

$enemies[$key] = implode( , , $value); } } $table =

Character Name: >
Real Name: >
Powers:
(Ctrl-click to
select multiple
powers)
Lair Location:
(address,
city, state, zip)
>
> > >
Alignment:
No characters . currently exist.

; ?>

Comic Book
Appreciation


Character Database

0) { $table =

; $table .=

; $table .=

; // build each table row $bg = ; while ($row = mysql_fetch_array($result)) { $bg = ($bg== F2F2FF ? E2E2F2 : F2F2FF ); $pow = ($powers[$row[ id ]]== ? none :$powers[$row[ id ]]); if (!isset($enemies) || ($enemies[$row[ id ]]== )) { $ene = none ; } else { $ene = $enemies[$row[ id ]]; } $table .=

.

.

; } $table .=

; $table .= Alias ; $table .= ; $table .= Name Alignment Powers Enemies
. $row[ alias ]. . $row[ name ] . . $row[ align ] . . $pow . . $ene .

; $table = str_replace( evil , evil , $table); $table = str_replace( good , good , 307 Building Databases
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Free php web host - Try It Out Managing the Characters The next

Monday, October 15th, 2007

Try It Out Managing the Characters The next file you re going to create will display a list of the characters in your database. 1. Enter the following code, and save it as charlist.php: alias ASC , 2 => name ASC , 3 => align ASC, alias ASC ); $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); $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()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $p[$row[ id ]][] = $row[ power ]; } foreach ($p as $key => $value) { $powers[$key] = implode( , , $value); } } $sql = SELECT c.id, n.alias . FROM char_main c . JOIN char_good_bad_link gb . JOIN char_main n . ON (c.id = gb.good_id AND n.id = gb.bad_id) . OR (n.id = gb.good_id AND c.id = gb.bad_id) ; $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) { 306 Chapter 10
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

This is the rest (Web hosting services) of the if statement.

Sunday, October 14th, 2007

This is the rest of the if statement. If there is even one power, a row is created that contains a delete button. If not, the script creates a row that simply states that no powers have yet been entered. $delbutton =

deleting will remove all associated powers
from characters as well — select wisely

; } else { $powerchk =

No Powers entered…

; $delbutton = ; $cols = 1; } ?> We have left off some of the HTML. We assume you know HTML well enough that we don t need to explain it. As you can see in the
tag, when the user clicks the Add Power or Delete Powers button, you ll be sending values to char_transact.php:
At this point, $powerchk either contains the No Powers display, or the built-up table columns. Either way, the script inserts $powerchk into the table. Note the open and close table definitions (
and

). You didn t add them to $powerchk earlier, but you did add the internal close/open definitions to create the columns as necessary.

In the following, $delbutton either contains the row with the delete button (if powers were found), or it s blank. That is how you control when it shows up, and this is where it s inserted into the table. The following code deals with the add button. Notice that it is called action and that it has a value of Add Power. When submitting a form, PHP passes these values on to the next page. Because you are using the post method on the form, you will have a $_POST variable called action that contains the value of the button. Because of this, and because all of your forms load char_transact.php, all of your buttons are named action and have different values so that you can determine what to do with the data that is sent. We go into more detail about this when we look at char_transact.php. 305 Building Databases
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.