- <?php
- $sPage_title = 'Random Tile Generator';
- include ('./includes/header.html');
- if (isset($_POST['submitted'])) {
- if (is_numeric($_POST['quantity'])) {
- require_once('../../../mysql_connect.php');
- for ($i = 1; $i <= $_POST['quantity']; $i++) {
- // Right now this doesn't fully populate all the information a tile should have. Just most of the main 'tiles' table.
- $sTile_name = rand(1, $_POST['quantity']) . ' GenTile ' . rand(35, 300);
- $iTile_price = rand(175, 9500);
- $iQuantity = rand(0,10000);
- $iNom_height = (rand(625, 48000) / 1000); // HOW DO I GENERATE FRACTIONS? This seems like the retarded or obvious way to do it.
- $iNom_width = (rand(625, 48000) / 1000);
- $iNom_thick = (rand(225, 500) / 1000);
- $iBox_tile_count = rand(0, 250);
- if ($iBox_tile_count < 25) {
- $iBox_tile_count = NULL; // Can be null, so this way it will be sometimes
- }
- $iLocal_supply = rand(0, 3);
- $iRating = rand(0,9);
- $query = "INSERT INTO tiles (tile_name, tile_price, quantity, nom_height, nom_width, nom_thick, box_tile_count, local_supply, rating) VALUES (
- '$sTile_name',
- '$iTile_price',
- '$iQuantity',
- '$iNom_height',
- '$iNom_width',
- '$iNom_thick',
- '$iBox_tile_count',
- '$iLocal_supply',
- '$iRating'
- );";
- $result = @mysql_query($query);
- }
- $query = "SELECT tile_id, tile_name, tile_price, quantity, nom_height, nom_width, nom_thick, box_tile_count, local_supply, rating FROM tiles";
- $result = @mysql_query($query);
- ?>
- <table>
- <tr>
- <th><b>Tile ID:</b></th>
- <th><b>Tile name:</b></th>
- <th><b>Price:</b></th>
- <th><b>Quantity:</b></th>
- <th><b>Height</b></th>
- <th><b>Width</b></th>
- <th><b>Thick:</b></th>
- <th><b>Box Count:</b></th>
- <th><b>Local Supply:</b></th>
- <th><b>Rating:</b></th>
- </tr>
- <?php
- $iResult_count = 0;
- if ($result) {
- while ($row = mysql_fetch_array($result)) {
- echo "\t<tr>\n\t\t<td>" . $row['tile_id'] . "</td>\n";
- echo "\t\t<td>" . $row['tile_name'] . "</td>\n";
- echo "\t\t<td>" . $row['tile_price'] . "</td>\n";
- echo "\t\t<td>" . $row['quantity'] . "</td>\n";
- echo "\t\t<td>" . $row['nom_height'] . "</td>\n";
- echo "\t\t<td>" . $row['nom_width'] . "</td>\n";
- echo "\t\t<td>" . $row['nom_thick'] . "</td>\n";
- echo "\t\t<td>" . $row['box_tile_count'] . "</td>\n";
- echo "\t\t<td>" . $row['local_supply'] . "</td>\n";
- echo "\t\t<td>" . $row['rating'] . "</td>\n\t</tr>\n";
- $iResult_count++;
- }
- }
- echo '</table>';
- mysql_close();
- } else {
- echo '<p class="error">Please input a valid tile quantity less than 1000</p>';
- }
- }
- if (isset($_POST['clear_it'])) {
- require_once('../../../mysql_connect.php');
- $query = "DELETE FROM tiles WHERE tile_id > 0";
- $result = @mysql_query($query);
- mysql_close();
- }
- ?>
- <p>This fills up the tile database with a bunch of randomly generated tiles.</p>
- <form action="generator.php" method="POST">
- <p>Number of Tiles: <input type="text" name="quantity" size="3" maxlength="3" /></p>
- <p><input type="submit" name="submitted" value="Generate!" /></p>
- </form>
- <?php
- if ($iResult_count > 1) {
- ?>
- <form action="generator.php" method="POST">
- <p><input type="submit" name="clear_it" value="Clear everything but ID 1!" /></p>
- </form>
- <?php
- }
- include ('./includes/footer.html');
- ?>