Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 3.24 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. $sPage_title = 'Random Tile Generator';
  3. include ('./includes/header.html');
  4.  
  5. if (isset($_POST['submitted'])) {
  6.        
  7.         if (is_numeric($_POST['quantity'])) {
  8.                
  9.                 require_once('../../../mysql_connect.php');
  10.  
  11.                 for ($i = 1; $i <= $_POST['quantity']; $i++) {
  12.  
  13.                         // Right now this doesn't fully populate all the information a tile should have. Just most of the main 'tiles' table.
  14.  
  15.                         $sTile_name = rand(1, $_POST['quantity']) . ' GenTile ' . rand(35, 300);
  16.                         $iTile_price = rand(175, 9500);
  17.                         $iQuantity = rand(0,10000);
  18.                         $iNom_height = (rand(625, 48000) / 1000); // HOW DO I GENERATE FRACTIONS? This seems like the retarded or obvious way to do it.
  19.                         $iNom_width = (rand(625, 48000) / 1000);
  20.                         $iNom_thick = (rand(225, 500) / 1000);
  21.                         $iBox_tile_count = rand(0, 250);
  22.                         if ($iBox_tile_count < 25) {
  23.                                 $iBox_tile_count = NULL; // Can be null, so this way it will be sometimes
  24.                         }
  25.                         $iLocal_supply = rand(0, 3);
  26.                         $iRating = rand(0,9);
  27.  
  28.                         $query = "INSERT INTO tiles (tile_name, tile_price, quantity, nom_height, nom_width, nom_thick, box_tile_count, local_supply, rating) VALUES (
  29.                                 '$sTile_name',
  30.                                 '$iTile_price',
  31.                                 '$iQuantity',
  32.                                 '$iNom_height',
  33.                                 '$iNom_width',
  34.                                 '$iNom_thick',
  35.                                 '$iBox_tile_count',
  36.                                 '$iLocal_supply',
  37.                                 '$iRating'
  38.                                 );";
  39.  
  40.                         $result = @mysql_query($query);
  41.                 }
  42.  
  43.                 $query = "SELECT tile_id, tile_name, tile_price, quantity, nom_height, nom_width, nom_thick, box_tile_count, local_supply, rating FROM tiles";
  44.  
  45.                 $result = @mysql_query($query);
  46. ?>
  47.  
  48. <table>
  49.         <tr>
  50.                 <th><b>Tile ID:</b></th>
  51.                 <th><b>Tile name:</b></th>
  52.                 <th><b>Price:</b></th>
  53.                 <th><b>Quantity:</b></th>
  54.                 <th><b>Height</b></th>
  55.                 <th><b>Width</b></th>
  56.                 <th><b>Thick:</b></th>
  57.                 <th><b>Box Count:</b></th>
  58.                 <th><b>Local Supply:</b></th>
  59.                 <th><b>Rating:</b></th>
  60.         </tr>
  61.  
  62. <?php
  63.                
  64.                 $iResult_count = 0;
  65.  
  66.                 if ($result) {
  67.                         while ($row = mysql_fetch_array($result)) {
  68.                                 echo "\t<tr>\n\t\t<td>" . $row['tile_id'] . "</td>\n";
  69.                                 echo "\t\t<td>" . $row['tile_name'] . "</td>\n";
  70.                                 echo "\t\t<td>" . $row['tile_price'] . "</td>\n";
  71.                                 echo "\t\t<td>" . $row['quantity'] . "</td>\n";
  72.                                 echo "\t\t<td>" . $row['nom_height'] . "</td>\n";
  73.                                 echo "\t\t<td>" . $row['nom_width'] . "</td>\n";
  74.                                 echo "\t\t<td>" . $row['nom_thick'] . "</td>\n";
  75.                                 echo "\t\t<td>" . $row['box_tile_count'] . "</td>\n";
  76.                                 echo "\t\t<td>" . $row['local_supply'] . "</td>\n";
  77.                                 echo "\t\t<td>" . $row['rating'] . "</td>\n\t</tr>\n";
  78.                                 $iResult_count++;
  79.                         }
  80.                 }
  81.  
  82.                 echo '</table>';
  83.  
  84.                 mysql_close();
  85.  
  86.         } else {
  87.  
  88.                 echo '<p class="error">Please input a valid tile quantity less than 1000</p>';
  89.  
  90.         }
  91. }
  92.  
  93. if (isset($_POST['clear_it'])) {
  94.        
  95.         require_once('../../../mysql_connect.php');
  96.  
  97.         $query = "DELETE FROM tiles WHERE tile_id > 0";
  98.         $result = @mysql_query($query);
  99.  
  100.         mysql_close();
  101. }
  102. ?>
  103.  
  104. <p>This fills up the tile database with a bunch of randomly generated tiles.</p>
  105. <form action="generator.php" method="POST">
  106.         <p>Number of Tiles: <input type="text" name="quantity" size="3" maxlength="3" /></p>
  107.         <p><input type="submit" name="submitted" value="Generate!" /></p>
  108. </form>
  109.  
  110. <?php
  111.  
  112. if ($iResult_count > 1) {
  113. ?>
  114.  
  115. <form action="generator.php" method="POST">
  116.         <p><input type="submit" name="clear_it" value="Clear everything but ID 1!" /></p>
  117. </form>
  118.  
  119. <?php
  120. }
  121.  
  122. include ('./includes/footer.html');
  123. ?>