Jump to content

bubblegum.anarchy

Members
  • Posts

    526
  • Joined

  • Last visited

    Never

Posts posted by bubblegum.anarchy

  1. The main difference is the supported date range - TIMESTAMP is more appropriate for storing current values used in all inserts and updates like a creation and modification timestamp, the range is from `1970-01-01 00:00:00` till partway though the yeay 2037 (according to the mysql manual).  DATETIME supports dates ranging from `1000-01-01 00:00:00` to `9999-12-31 23:59:59` and is more appropriate for anniversary dates, especially those prior to 1970.  TIMESTAMP values are also automatically set to the current date and time if no value is provided or a NULL value is assigned.

  2. Confirm that the queries used on the webpage are what is slowing down the page load time by performing each query via a query browser, you may find that a particular query is slower than others and can be optimized in some way... oh and run an optimize/analyze on the database tables.

  3. SELECT speed.* FROM speed
         INNER JOIN ( SELECT competitor, min(speed.time) AS time FROM speed GROUP BY competitor ) AS fastest
              ON speed.competitor = fastest.competitor AND speed.time = fastest.time
    ORDER BY speed.time
    

  4. Insert the order_desc table information first and store the last insert id like this:

     

    $order_id = mysql_insert_id();

     

    Then insert each order item table information with order_id set to $order_id.

     

  5. See if you can wrap your head around this instead:

     

    DROP TABLE IF EXISTS site;
    CREATE TABLE site (
         id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'unique identifier',
         label VARCHAR(100) NOT NULL DEFAULT 'Label not defined' COMMENT 'site label',
         address VARCHAR(255) NOT NULL DEFAULT 'Address not defined' COMMENT 'site address',
         PRIMARY KEY (id)
    ) TYPE=MyISAM;
    
    DROP TABLE IF EXISTS room;
    CREATE TABLE room (
         id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'unique identifier',
         label VARCHAR(100) NOT NULL DEFAULT 'Label not defined' COMMENT 'room label',
         layer_limit INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'layer limit',
         column_limit INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'layer limit',
         row_limit INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'layer limit',
         PRIMARY KEY (id)
    ) TYPE=MyISAM;
    
    DROP TABLE IF EXISTS server;
    CREATE TABLE server (
         id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'unique identifier',
         site_id INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'site.id foreign key reference',
         room_id INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'room.id foreign key reference',
         layer_num INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'layer position',
         column_num INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'column position',
         row_num INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'row position',
         PRIMARY KEY (id),
         INDEX (site_id)
    ) TYPE=MyISAM;
    
    INSERT IGNORE INTO site (label, address) VALUES ('Primary', '101 Brick Road');
    INSERT IGNORE INTO room (label, layer_limit, column_limit, row_limit) VALUE ('White Room', 3, 3, 3);
    
    INSERT IGNORE INTO server (site_id, room_id, layer_num, column_num, row_num) VALUE 
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 1, 1),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 1, 2),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 1, 3),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 2, 1),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 2, 2),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 2, 3),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 3, 1),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 3, 2),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 1, 3, 3),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 2, 1, 1),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 2, 1, 2),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 2, 1, 3),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 2, 2, 1),
    ((SELECT id FROM site WHERE label = 'Primary'), (SELECT id FROM room WHERE label = 'White Room'), 2, 2, 3);
    
    SELECT server.* FROM server 
         INNER JOIN site ON site_id = site.id AND site.label = 'Primary'
         INNER JOIN room ON room_id = room.id AND room.label = 'White Room'
    ;
    
    SELECT layer_num AS next_available_layer, count(*) FROM server 
         INNER JOIN site ON site_id = site.id AND site.label = 'Primary'
         INNER JOIN room ON room_id = room.id AND room.label = 'White Room'
    GROUP BY layer_num
    HAVING count(*) < ( SELECT column_limit * row_limit FROM room WHERE label = 'White Room' );
    

     

    That last query returns the next available layer and nothing is returned that the room is full.... try and extrapolate that query to provide the next available column and row... well... this is what I would do if confronted with the same task.

  6. hmm.. I am a little confused, according to the above picture I could identify any box (server) with only three bits of information, the layer, the column and the position... whats the point of the other information (rack and level)?

     

    note: a rack can be identified by a column and a position

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.