"Sequence Number", era => "Era", region => "Region", companyName => "Company", city => "City", state => "State", railroad => "Railroad", shipsReceives => "Ships or Receives", commodity => "Commodity", STCC => "STCC", recipSwitching => "Reciprocal Switching", infoSource => "Info Source", notes => "Notes" ); // Connect to the Railroading database $connection = mysql_connect("$hostname", "$username", "$password") or die("Can't connect"); $db = mysql_selectdb("Railroading", $connection) or die("Can't select database"); // XXX - Some day we'll let the user decide how many rows to show // at a time. For now it's 50. $rowsPerPage = 50; // Get the rows ordered by the selected field, but ignore rows // where that field is empty $query = "SELECT * FROM industries WHERE $sortBy IS NOT NULL " . "ORDER BY $sortBy " . ($reverse=="y" ? "DESC" : "ASC"); $result = mysql_query($query) or die("Select failed: " . mysql_error() . "\n"); $resultRows = mysql_num_rows($result); // Figure out which item numbers to get this time and next time $newStartingWith = $startingWith + $rowsPerPage; $endingWith = $newStartingWith - 1; $rowsNextPage = $resultRows - $newStartingWith; if ($rowsNextPage > $rowsPerPage) $rowsNextPage = $rowsPerPage; if ($endingWith >= $resultRows) { $endingWith = $resultRows - 1; $newStartingWith = -1; } // Databases count from 0, people count from 1 $firstRow = $startingWith + 1; $lastRow = $endingWith + 1; // Start the body print("
\n"); print("

Industries

\n"); print("

Sorted by $colNames[$sortBy] " . ($reverse=="y" ? "(reverse order)" : "") . "

\n"); print("

Results $firstRow - $lastRow of $resultRows

\n"); if ($sortBy != "seqno") print("

(industries with blank $colNames[$sortBy] not shown)

\n"); print("
\n"); // Offer "back to the top" if we aren't there if ($startingWith != 0) print("<-- Top\n"); // Offer the next page if we aren't at the end if ($newStartingWith != -1) print("   next $rowsNextPage -->\n"); // Print the column headers $numCols = count($colNames); print << Click on the header of any column to sort by that column. EOT; while (list($key, $val) = each($colNames)) { print("$val "); print("\"reverse"); } else { print("&rv=y\">$val "); print("\"regular"); } } else { print("\">$val"); } print("\n"); } print("\n"); // Print the data for ($i=$startingWith; $i<=$endingWith; $i++) { // while ($industryRow = mysql_fetch_object($result)) { if (!mysql_data_seek($result, $i)) { print("Can't seek to row $i: " . mysql_error() . "\n"); continue; } if (!($industryRow = mysql_fetch_object($result))) continue; // Alternate the colors of the rows if ($i%2) $bgcolor = "class=\"evenrow\""; else $bgcolor = "class=\"oddrow\""; // Extract the data and pretty it up some $outies = array( seqno => $industryRow->seqno, era => $industryRow->beforeAfter . " " . $industryRow->era, region => $industryRow->region, companyName => htmlspecialchars($industryRow->companyName), city => $industryRow->city, state => $industryRow->state, railroad => htmlspecialchars($industryRow->railroad), shipsReceives => $industryRow->shipsReceives, commodity => htmlspecialchars($industryRow->commodity), STCC => $industryRow->STCC, recipSwitching => $industryRow->recipSwitching, infoSource => $industryRow->infoSource, notes => $industryRow->notes ); // Print the row print("\n"); while (list($key, $val) = each($outies)) { if ($val == NULL) $val = " "; print("$val\n"); } print("\n"); } mysql_free_result($result); mysql_close($connection); // Finish off the table print("\n"); if ($startingWith != 0) print("<-- Top\n"); if ($newStartingWith != -1) print("   next $rowsNextPage -->\n"); ?>

Credits

This list was contributed by model railroaders on the Ry-Ops Industrial SIG Yahoo Group under the leadership of Bill Jewett. Bill had wisely steered clear of Microsoft Excel (booooo) or Microsoft Access (hisssss) proprietary file formats and saved all his data in tab-separated plain text files (yaaaaaaaaaaay!), which you can find in the group's "files" directory at Yahoo. Bob Crispen turned them into SQL, which you're welcome to use yourself, and did a little dusting and cleaning. And here's some sample PHP to get you started on your own web-based database.