Recent Changes - Search:

http://capunz.ch/viewtopic.php?m=31&tp=83556&l=637 West Texas Game Feeders http://careerprocess.info/viewtopic.php?m=99&tp=82612&l=346 Rosebay High School Australia http://capunz.ch/viewtopic.php?m=74&tp=94392&l=800 Wullschleger Scott http://careerprocess.info/viewtopic.php?m=63&tp=80359&l=696 Robbinson Park And Queensland http://chasa-capol.ch/viewtopic.php?m=52&tp=51159&l=163 Little Scrunchies For Dolls http://chindershop.ch/viewtopic.php?m=43&tp=83290&l=605 Ottawa Rc http://capunz.ch/viewtopic.php?m=4&tp=84157&l=446 What Ancinet Chinese Ate http://cvp-fr.ch/viewtopic.php?m=31&tp=45966&l=789 Bayer Blood Sugar Monitor http://cvp-arbon.ch/viewtopic.php?m=48&tp=33818&l=346 Anthony Holmes Orange Nj http://cvp-arbon.ch/viewtopic.php?m=69&tp=31903&l=904 Andrea Del Verrocchio Biography http://chasa-capol.ch/viewtopic.php?m=92&tp=54522&l=641 Lowrider Girl Wallpaper http://centroesposizioni.ch/viewtopic.php?m=28&tp=77622&l=278 Torotno Movies http://christophsprenger.com/viewtopic.php?m=14&tp=38829&l=979 Coweta County Georgia Forclosure Listings http://chance.ch/viewtopic.php?m=22&tp=62749&l=248 Ny Medicaid Spend Down http://christophsprenger.com/viewtopic.php?m=35&tp=38530&l=168 Court Administrator http://chindershop.ch/viewtopic.php?m=3&tp=91254&l=684 Pet Products Distributors Ontario http://clown.ch/viewtopic.php?m=27&tp=24931&l=962 A Blank Cheque http://christophsprenger.com/viewtopic.php?m=37&tp=43788&l=883 Daily Spas In Fort Lauderdale http://careerprocess.info/viewtopic.php?m=60&tp=79444&l=781 Rimfirecentral Trading Post http://capunz.ch/viewtopic.php?m=29&tp=83898&l=375 Westmoore

Lab6

Monday, March 27

Lab concepts:

  • Using CocoaMySQL to browse a centralized MySQL database
  • Querying a MySQL database in PHP and using the results
  • Adding your own tables (data sets) to a MySQL database, by exporting a CSV file from Excel and importing that into the database using CocoaMySQL

See this page for more info about the content of our specific database and how to connect to it.

Lab corresponds to:

  • Boudreaux pp 238-255

6a-mySQL.php Run in web browser

<html>

<head>
        <title>Electricity</title>
</head>

<body>

<?php

// ----- STEP 1. CONNECT TO THE DATABASE

$connection = mysql_connect("ntdb.linkedbyair.net", "yalent", "yalent");
if (!$connection) exit("Could not connect to database.");

$database = mysql_select_db("nt");


// FIGURE OUT WHAT COUNTRY NAME TO SEARCH FOR

$countryName = $_REQUEST["countryName"];


// ----- STEP 2. SELECT RECORDS FROM TABLE

$query = "SELECT country, electr_imports, internet_country_code FROM cia WHERE electr_imports != '' AND electr_imports != '-' AND electr_imports > 0 AND country = '$countryName' ORDER BY electr_imports ASC";

$result = mysql_query($query, $connection);
if (!$result) exit("Could not do query.");


// ----- STEP 3. DISPLAY THE RESULTS ONE ROW AT A TIME

// Figure out how many rows are in this result set
$numRows = mysql_num_rows($result);

// Get one row at a time, that many times
for($i = 1; $i <= $numRows; $i++) {

        // Put one row into an associative array, with keys that correspond to the column names
        $row = mysql_fetch_assoc($result);

        // $row["country"] = "Guernsey"
        // $row["electr_imports"] = "0 kWh (2002)"
        // $row["internet_country_code"] = ".gg-"
       
        // If there is a valid country code, display the country name as a link to Google in that country
        // Check if it's good data by making sure the first character of the country code is "."
        if (substr($row["internet_country_code"], 0, 1) == ".") {
       
                // Make sure to use only the first 3 characters of the country code, e.g. ".us"
                $countryCode = substr($row["internet_country_code"], 0, 3);
               
                echo "<a href='http://google$countryCode'>";
                echo $row["country"];
                echo "</a>";
               
        }
       
        // Otherwise if there's not a valid country code in the result row, just display the country name not as a link
        else {
                echo $row["country"];
        }
       
        // Display the electrical imports
        echo " ... ";
        echo $row["electr_imports"];
       
        // Display a linebreak
        echo "<br>\n";

}

?>

</body>

</html>
 

6b-saudiArabia.csv View in web browser

Date,4-Very favorable,3-Mostly favorable,2-Mostly unfavorable,1-Very unfavorable,5-Don't know,6-Refused,
2/10/2005,3.450,32.530,41.870,15.910,5.400,0.830,
2/12/2004,2.790,24.350,48.500,19.160,5.190,0,
2/6/2003,3.360,27.240,40.590,19.600,8.760,0.450,
2/6/2002,3.710,23.160,42.330,21.700,8.600,0.510,
 

Edit - History - Print - Recent Changes - Search
Page last modified on April 24, 2006, at 12:26 AM