php/mysql table

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

okay i semi understand what you wrote. I am not too familiar with the array function of PHP.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

I've been away from a computer for awhile and cutting down a big (dead) tree and turning it into lawn furniture. I agree with bigwebmaster about the loop mysql pull. I based my examples based on the code you provided since I'm unfamiliar with your coding level.

This does seem to be an example of scope creep since my example was simple and didn't know the full outcome of what you were looking for. my example can be made to do that but it feels hacked.

what is the end result suppose to look and function like. also what are the all of the data base columns in both tables. you can change their names to keep your structure safe just make sure that columns in the tables that are suppose to link together are the same.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

This system is only used as an internal system.
well you got the overall look done right.

You have table: BitMachine
id - machine

The next table is: bits
Image

Now when it shows it only shows the serial/crown/size/load wk and if its hot/ultra hot

Image


As in this picture its showing that all orders that are Hot and ultra hot are on top of all pending orders. ultra hot orders go on top of all pending orders for that machine.

Now once a bit is started it will need to go up into the In machine area.

on the rows hot/ultra hot/on machine is using a 0 or 1 to say if it is no or yes for hotness/on machine

the way the bit moves to if on machine or in que is already done. I am just trying to get it to display correctly.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

How big are those MySQL tables? May I suggest a change in structure?

Instead of having a ulta-hot, hot columns, you could have temperature. 1 being ulta hot, 2 being hot and 3 being normal (as values for column 'temperature'). And when you are retrieving the stuff from the database just have it order by temperature.
SQL Code: [ Select ]
SELECT * FROM bits WHERE COLUMN = value ORDER BY temperature ASC

Something like that is what I'm talking about.
Code: [ Select ]
| id | serial |    crown | type | size |  status | load wk | temperature | bitdate | onmachine |
------------------------------------------------------------------------------------------------
| 104|T7040837|T588X20316|HYBRID|18.125|Mazak 670|       14|            3|    4-May|          1|
  1. | id | serial |    crown | type | size |  status | load wk | temperature | bitdate | onmachine |
  2. ------------------------------------------------------------------------------------------------
  3. | 104|T7040837|T588X20316|HYBRID|18.125|Mazak 670|       14|            3|    4-May|          1|

I believe that the following SQL is what you need (instead of having an SQL inside that loop as you have it at the moment.
SQL Code: [ Select ]
SELECT * FROM bits WHERE STATUS = (SELECT machine FROM BitMachine)
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

i do agree it would make it easier to change up the database the way bogey suggested but if that's not a possibility then making the array structure that bigwebmaster suggested is the way to go.

on the SQL statement I'm continuing to run with the mysql in a loop for now since my test file is already running that but i can also make one the doesn't pull in a loop once i figure out if this is the way you want to run it.

This is my test file It is setup so i don't need a db connection like before and needs to have the for's change to while's but this demonstrates the array structure I'm almost out of time that i can mess with it today so i'll post what i have.

PHP Code: [ Select ]
    <?php
 
   function build_table($row, $type, $temp) {
     
      switch($type) {
        case 'STEEL': echo '<div style="background-color:#FF9999;">'; break;
        case 'SLIM': echo '<div style="background-color:#9999FF;">'; break;
        case 'KYMERA': echo '<div style="background-color:#FF2626;">'; break;
        case 'HYBRID': echo '<div style="background-color:#FF2626;">'; break;
        case 'EZC': echo '<div style="background-color:#FFFF26;">'; break;
        case 'RWD': echo '<div style="background-color:#FF9326;">'; break;
        case 'EZR': echo '<div style="background-color:#FFFF26;">'; break;
        case 'EZB': echo '<div style="background-color:#FFFF26;">'; break;
        default : echo '<div>';
       }
       
      echo '<a href="operator.php?id='. $row['serial'] .'"><div style="border:solid; border-color:#000000;">
             <table border="0" cellspacing="0" cellpadding="0" width="100%">';
       
      switch($temp) {
        case 'ultrahot': echo'<tr><td><div style="background-color:#FF0000;">*Ultra Hot*</div></td></tr>'; break;
        case 'hot': echo'<tr><td><div style="background-color:#FF0000;">*HOT*</div></td></tr>'; break;
      }
     
      echo '<tr>
             <td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>
           </tr>
           <tr>
             <td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>
           </tr>
           <tr>
             <td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>
           </tr>
         </table></div></a></div>';
       
     
     
   }
 
   $db1 = array(
      array('machine' => 'mac1'),
      array('machine' => 'mac2'),
      array('machine' => 'mac3'),
      array('machine' => 'mac4'),
      array('machine' => 'mac5'),
      array('machine' => 'mac6'),
      array('machine' => 'mac7'),
      array('machine' => 'mac8')
      );
 
   $db2 = array(
      "mac1" => array(
         array("id" => 1, "serial" => 123, "crown" => 't588', "type" => 'HYBRID', "status" => 'mac1', "load_wk" => 5, "hot" => 1, "ultrahot" => 0, "bitdate" => 14, "onmachine" => 1),
         array("id" => 2, "serial" => 456, "crown" => 't788', "type" => 'HYBRID', "status" => 'mac1', "load_wk" => 6, "hot" => 0, "ultrahot" => 1, "bitdate" => 14, "onmachine" => 1)),
      "mac2" => array(array("id" => 3, "serial" => 789, "crown" => 't855', "type" => 'SLIM', "status" => 'mac2', "load_wk" => 7, "hot" => 1, "ultrahot" => 0, "bitdate" => 16, "onmachine" => 0)),
      "mac3" => array(array("id" => 5, "serial" => 147, "crown" => 't955', "type" => 'SLIM', "status" => 'mac3', "load_wk" => 8, "hot" => 0, "ultrahot" => 0, "bitdate" => 13, "onmachine" => 0)),
      "mac5" => array(array("id" => 7, "serial" => 258, "crown" => 't155', "type" => 'HYBRID', "status" => 'mac4', "load_wk" => 0, "hot" => 0, "ultrahot" => 0, "bitdate" => 15, "onmachine" => 1)),
      "mac5" => array(array("id" => 9, "serial" => 369, "crown" => 't255', "type" => 'HYBRID', "status" => 'mac5', "load_wk" => 10, "hot" => 0, "ultrahot" => 1, "bitdate" => 15, "onmachine" => 0))
      );
     
    $table      = array();
    $table_keys = array();
    $ii=0;
     
    foreach($db1 as $mch) {
        $table_keys[] = $mch['machine'];
      if(array_key_exists($mch['machine'], $db2)){
        foreach ($db2[$mch['machine']] as $ord) {
         $onmach = ($ord['onmachine']) ? 'yes' : 'no';
         if($ord['hot']) {
            $table[$mch['machine']][$onmach]['hot'] = $ord;
         } else if($ord['ultrahot']) {
            $table[$mch['machine']][$onmach]['ultrahot'] = $ord;
         } else {
            $table[$mch['machine']][$onmach]['normal'] = $ord;
         }
         $ii++;
        }
     
      $ii=0;
      }
    }$ii=0;
   ?>
   <div style="overflow:auto; width:100%; height:100%">
         <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
              </tr>
              <tr>
               <?php  foreach($table_keys as $value) {
                  echo '<td align="center">In Machine<div style="overflow:auto; height:200px; width:110px;">';
              foreach($table[$value]['yes'] as $key => $table_row) {
               
               if($key == 'ultrahot') {
                  build_table($table_row, $table_row['type'], 'ultrahot');
               }
               
               if($key == 'hot') {
                  build_table($table_row, $table_row['type'], 'hot');
               }
               
               if($key == 'normal') {
                  build_table($table_row, $table_row['type'], 'normal');
               }
               
              }
              echo '</div></td>';
             
            }
           
              ?>
                  </tr>
              <tr>
               <?php foreach($table_keys as $value) {
                  echo '<td align="center">Machine Que<div style="overflow:auto; height:200px; width:110px;">';
              foreach($table[$value]['no'] as $key => $table_row) {
               
               if($key == 'ultrahot') {
                  build_table($table_row, $table_row['type'], 'ultrahot');
               }
               
               if($key == 'hot') {
                  build_table($table_row, $table_row['type'], 'hot');
               }
               
               if($key == 'normal') {
                  build_table($table_row, $table_row['type'], 'normal');
               }
               
              }
              echo '</td>';
         
            }
              ?>
              </tr>
              </table>
           </div>
 
  1.     <?php
  2.  
  3.    function build_table($row, $type, $temp) {
  4.      
  5.       switch($type) {
  6.         case 'STEEL': echo '<div style="background-color:#FF9999;">'; break;
  7.         case 'SLIM': echo '<div style="background-color:#9999FF;">'; break;
  8.         case 'KYMERA': echo '<div style="background-color:#FF2626;">'; break;
  9.         case 'HYBRID': echo '<div style="background-color:#FF2626;">'; break;
  10.         case 'EZC': echo '<div style="background-color:#FFFF26;">'; break;
  11.         case 'RWD': echo '<div style="background-color:#FF9326;">'; break;
  12.         case 'EZR': echo '<div style="background-color:#FFFF26;">'; break;
  13.         case 'EZB': echo '<div style="background-color:#FFFF26;">'; break;
  14.         default : echo '<div>';
  15.        }
  16.        
  17.       echo '<a href="operator.php?id='. $row['serial'] .'"><div style="border:solid; border-color:#000000;">
  18.              <table border="0" cellspacing="0" cellpadding="0" width="100%">';
  19.        
  20.       switch($temp) {
  21.         case 'ultrahot': echo'<tr><td><div style="background-color:#FF0000;">*Ultra Hot*</div></td></tr>'; break;
  22.         case 'hot': echo'<tr><td><div style="background-color:#FF0000;">*HOT*</div></td></tr>'; break;
  23.       }
  24.      
  25.       echo '<tr>
  26.              <td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>
  27.            </tr>
  28.            <tr>
  29.              <td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>
  30.            </tr>
  31.            <tr>
  32.              <td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>
  33.            </tr>
  34.          </table></div></a></div>';
  35.        
  36.      
  37.      
  38.    }
  39.  
  40.    $db1 = array(
  41.       array('machine' => 'mac1'),
  42.       array('machine' => 'mac2'),
  43.       array('machine' => 'mac3'),
  44.       array('machine' => 'mac4'),
  45.       array('machine' => 'mac5'),
  46.       array('machine' => 'mac6'),
  47.       array('machine' => 'mac7'),
  48.       array('machine' => 'mac8')
  49.       );
  50.  
  51.    $db2 = array(
  52.       "mac1" => array(
  53.          array("id" => 1, "serial" => 123, "crown" => 't588', "type" => 'HYBRID', "status" => 'mac1', "load_wk" => 5, "hot" => 1, "ultrahot" => 0, "bitdate" => 14, "onmachine" => 1),
  54.          array("id" => 2, "serial" => 456, "crown" => 't788', "type" => 'HYBRID', "status" => 'mac1', "load_wk" => 6, "hot" => 0, "ultrahot" => 1, "bitdate" => 14, "onmachine" => 1)),
  55.       "mac2" => array(array("id" => 3, "serial" => 789, "crown" => 't855', "type" => 'SLIM', "status" => 'mac2', "load_wk" => 7, "hot" => 1, "ultrahot" => 0, "bitdate" => 16, "onmachine" => 0)),
  56.       "mac3" => array(array("id" => 5, "serial" => 147, "crown" => 't955', "type" => 'SLIM', "status" => 'mac3', "load_wk" => 8, "hot" => 0, "ultrahot" => 0, "bitdate" => 13, "onmachine" => 0)),
  57.       "mac5" => array(array("id" => 7, "serial" => 258, "crown" => 't155', "type" => 'HYBRID', "status" => 'mac4', "load_wk" => 0, "hot" => 0, "ultrahot" => 0, "bitdate" => 15, "onmachine" => 1)),
  58.       "mac5" => array(array("id" => 9, "serial" => 369, "crown" => 't255', "type" => 'HYBRID', "status" => 'mac5', "load_wk" => 10, "hot" => 0, "ultrahot" => 1, "bitdate" => 15, "onmachine" => 0))
  59.       );
  60.      
  61.     $table      = array();
  62.     $table_keys = array();
  63.     $ii=0;
  64.      
  65.     foreach($db1 as $mch) {
  66.         $table_keys[] = $mch['machine'];
  67.       if(array_key_exists($mch['machine'], $db2)){
  68.         foreach ($db2[$mch['machine']] as $ord) {
  69.          $onmach = ($ord['onmachine']) ? 'yes' : 'no';
  70.          if($ord['hot']) {
  71.             $table[$mch['machine']][$onmach]['hot'] = $ord;
  72.          } else if($ord['ultrahot']) {
  73.             $table[$mch['machine']][$onmach]['ultrahot'] = $ord;
  74.          } else {
  75.             $table[$mch['machine']][$onmach]['normal'] = $ord;
  76.          }
  77.          $ii++;
  78.         }
  79.      
  80.       $ii=0;
  81.       }
  82.     }$ii=0;
  83.    ?>
  84.    <div style="overflow:auto; width:100%; height:100%">
  85.          <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  86.               <tr>
  87.                 <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  88.               </tr>
  89.               <tr>
  90.                <?php  foreach($table_keys as $value) {
  91.                   echo '<td align="center">In Machine<div style="overflow:auto; height:200px; width:110px;">';
  92.               foreach($table[$value]['yes'] as $key => $table_row) {
  93.                
  94.                if($key == 'ultrahot') {
  95.                   build_table($table_row, $table_row['type'], 'ultrahot');
  96.                }
  97.                
  98.                if($key == 'hot') {
  99.                   build_table($table_row, $table_row['type'], 'hot');
  100.                }
  101.                
  102.                if($key == 'normal') {
  103.                   build_table($table_row, $table_row['type'], 'normal');
  104.                }
  105.                
  106.               }
  107.               echo '</div></td>';
  108.              
  109.             }
  110.            
  111.               ?>
  112.                   </tr>
  113.               <tr>
  114.                <?php foreach($table_keys as $value) {
  115.                   echo '<td align="center">Machine Que<div style="overflow:auto; height:200px; width:110px;">';
  116.               foreach($table[$value]['no'] as $key => $table_row) {
  117.                
  118.                if($key == 'ultrahot') {
  119.                   build_table($table_row, $table_row['type'], 'ultrahot');
  120.                }
  121.                
  122.                if($key == 'hot') {
  123.                   build_table($table_row, $table_row['type'], 'hot');
  124.                }
  125.                
  126.                if($key == 'normal') {
  127.                   build_table($table_row, $table_row['type'], 'normal');
  128.                }
  129.                
  130.               }
  131.               echo '</td>';
  132.          
  133.             }
  134.               ?>
  135.               </tr>
  136.               </table>
  137.            </div>
  138.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

I can change the DB if need to be.
the db can be big.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Quick question is there any other info in the bitMachine table you're using besides the machine name?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

no just id and machine is in the bitmachine table.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

SO I got fed up with the way my code was looking and actually built a dummy database. The column i use "name" is equal to your "machine"

This uses one query that contains a LEFT JOIN so that all of your machines will show up even if you do not have bits/orders on them it also uses some helper functions i wrote to make the source code nicer to read they can be removed if you choose to this version is more O.O. based to make changes to it faster. I've commented it to provide a bit of insight to the code.

PHP Code: [ Select ]
<?php
 
// Initialize
require_once('classes/initialize.php');
 
// These are functions to help make the code nicer and easier to read and by all means not required
// This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
function tab($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\t", $number);
   
}
 
// This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
function hs($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\r\n", $number);
   
}
 
// This function will build a string with a certain number of repeats. Example \r\n\r\n
function repeat_string($type, $number = 1) {
   
   // Make a return var
   $return = array();
   
   // Loop the number
   for($i=0; $i < $number; $i++) {
     
      // Add the tab
      $return[] = $type;
     
   }
   
   // Return the hard space
   return implode('', $return);
   
}
 
// This function is a pretty vardump
function pd($input) {
   echo '<pre>'; var_dump($input); echo '</pre>';  
}
// The functions above are to help make the code nicer and easier to read and by all means not required.
 
 
 
// This function will build out the inner table for all cases
function build_table($row, $type, $temp) {
   
   // Crrate an array to hold the table
   $return = array();
   
   // Setup the surrounding div tag to properly color the table
   switch($type) {
      case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
      case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
      case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
      case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      default :      $return[] = tab(5) .'<div>';
   }
   
   // Start building the output
   $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
   $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
   $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
   
   // Take their temperature and add to the output if their temperature matches
   switch($temp) {
      case 'ultrahot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
         
      case 'hot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
   }
   
   // Finish building the output
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(8) .'</table>';
   $return[] = tab(7) .'</div>';
   $return[] = tab(6) .'</a>';
   $return[] = tab(5) .'</div>';
   
   // Join and return the output
   return implode(hs(), $return);
   
}
 
// This function will build and return the table row
function build_row($keys, $rows, $type) {
   
   // Add return array we must.
   $return = array();
   
   // What type it is do we know. Hmmmm, yes.
   switch($type) {
      case 'yes': $text = 'In Machine'; break;
      case 'no': $text = 'Machine Que'; break;
   }
   
   // Loop through the table keys to build the columns
   foreach($keys as $value) {
     
      // Start the output
      $return[] = tab(3) . '<td align="center">';
      $return[] = tab(4) . $text;
      $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
     
      // Make sure we have an array
      if(is_array($rows[$value][$type])) {
     
         // Loop through the values that are in the on machine row of the table
         foreach($rows[$value][$type] as $key => $table_row) {
           
            // Check for NULL
            if($table_row['status']) {
           
               // Build the ultra hot table
               if($key == 'ultrahot') {
                  $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
               }
               // Build the hot table
               if($key == 'hot') {
                   $return[] = build_table($table_row, $table_row['type'], 'hot');
               }
               
               // Build the normal table
               if($key == 'normal') {
                   $return[] = build_table($table_row, $table_row['type'], 'normal');
               }
           
            }
         
         }
     
      }
 
      $return[] = tab(4) . '</div>';
      $return[] = tab(3) . '</td>';
 
   }
   
   // Join and return the output
   return implode(hs(), $return);
   
}
         
// Set SQL Query
$query = "
   SELECT `machine`.`name`, `bits`.*
   FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
";
 
// Execute
$results_key = $db->execute($query);
 
// Make the arrays to hold the table info
$table      = array();
$table_keys = array();
 
// Loop the results
while($row = $db->get_row($results_key)) {
   
   // Set the table header
   $table_keys[] = $row['name'];
   
   // Check to see if this bit is on the machine.
   $on_machine = ($row['onmachine']) ? 'yes' : 'no';
   
   // Sort by temperature starting with ultrahot
   if($row['ultrahot']) {
      $table[$row['name']][$on_machine]['ultrahot'] = $row;
   } else if($row['hot']) {
      $table[$row['name']][$on_machine]['hot'] = $row;
   } else {
      $table[$row['name']][$on_machine]['normal'] = $row;
   }
   
}
 
?>
 
<div style="overflow:auto; width:100%; height:100%">
   <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
      <tr>
         <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, 'yes'); ?>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, 'no'); ?>
      </tr>
   </table>
</div>
 
  1. <?php
  2.  
  3. // Initialize
  4. require_once('classes/initialize.php');
  5.  
  6. // These are functions to help make the code nicer and easier to read and by all means not required
  7. // This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
  8. function tab($number = 1) {
  9.    
  10.    // Call repeat_string and return the tabs
  11.    return repeat_string("\t", $number);
  12.    
  13. }
  14.  
  15. // This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
  16. function hs($number = 1) {
  17.    
  18.    // Call repeat_string and return the tabs
  19.    return repeat_string("\r\n", $number);
  20.    
  21. }
  22.  
  23. // This function will build a string with a certain number of repeats. Example \r\n\r\n
  24. function repeat_string($type, $number = 1) {
  25.    
  26.    // Make a return var
  27.    $return = array();
  28.    
  29.    // Loop the number
  30.    for($i=0; $i < $number; $i++) {
  31.      
  32.       // Add the tab
  33.       $return[] = $type;
  34.      
  35.    }
  36.    
  37.    // Return the hard space
  38.    return implode('', $return);
  39.    
  40. }
  41.  
  42. // This function is a pretty vardump
  43. function pd($input) {
  44.    echo '<pre>'; var_dump($input); echo '</pre>';  
  45. }
  46. // The functions above are to help make the code nicer and easier to read and by all means not required.
  47.  
  48.  
  49.  
  50. // This function will build out the inner table for all cases
  51. function build_table($row, $type, $temp) {
  52.    
  53.    // Crrate an array to hold the table
  54.    $return = array();
  55.    
  56.    // Setup the surrounding div tag to properly color the table
  57.    switch($type) {
  58.       case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
  59.       case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
  60.       case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  61.       case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  62.       case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  63.       case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
  64.       case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  65.       case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  66.       default :      $return[] = tab(5) .'<div>';
  67.    }
  68.    
  69.    // Start building the output
  70.    $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
  71.    $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
  72.    $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
  73.    
  74.    // Take their temperature and add to the output if their temperature matches
  75.    switch($temp) {
  76.       case 'ultrahot':
  77.          $return[] = tab(9) .'<tr>';
  78.          $return[] = tab(10) .'<td>';
  79.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
  80.          $return[] = tab(10) .'</td>';
  81.          $return[] = tab(9) .'</tr>';
  82.          break;
  83.          
  84.       case 'hot':
  85.          $return[] = tab(9) .'<tr>';
  86.          $return[] = tab(10) .'<td>';
  87.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
  88.          $return[] = tab(10) .'</td>';
  89.          $return[] = tab(9) .'</tr>';
  90.          break;
  91.    }
  92.    
  93.    // Finish building the output
  94.    $return[] = tab(9) .'<tr>';
  95.    $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
  96.    $return[] = tab(9) .'</tr>';
  97.    $return[] = tab(9) .'<tr>';
  98.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
  99.    $return[] = tab(9) .'</tr>';
  100.    $return[] = tab(9) .'<tr>';
  101.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
  102.    $return[] = tab(9) .'</tr>';
  103.    $return[] = tab(8) .'</table>';
  104.    $return[] = tab(7) .'</div>';
  105.    $return[] = tab(6) .'</a>';
  106.    $return[] = tab(5) .'</div>';
  107.    
  108.    // Join and return the output
  109.    return implode(hs(), $return);
  110.    
  111. }
  112.  
  113. // This function will build and return the table row
  114. function build_row($keys, $rows, $type) {
  115.    
  116.    // Add return array we must.
  117.    $return = array();
  118.    
  119.    // What type it is do we know. Hmmmm, yes.
  120.    switch($type) {
  121.       case 'yes': $text = 'In Machine'; break;
  122.       case 'no': $text = 'Machine Que'; break;
  123.    }
  124.    
  125.    // Loop through the table keys to build the columns
  126.    foreach($keys as $value) {
  127.      
  128.       // Start the output
  129.       $return[] = tab(3) . '<td align="center">';
  130.       $return[] = tab(4) . $text;
  131.       $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
  132.      
  133.       // Make sure we have an array
  134.       if(is_array($rows[$value][$type])) {
  135.      
  136.          // Loop through the values that are in the on machine row of the table
  137.          foreach($rows[$value][$type] as $key => $table_row) {
  138.            
  139.             // Check for NULL
  140.             if($table_row['status']) {
  141.            
  142.                // Build the ultra hot table
  143.                if($key == 'ultrahot') {
  144.                   $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
  145.                }
  146.                // Build the hot table
  147.                if($key == 'hot') {
  148.                    $return[] = build_table($table_row, $table_row['type'], 'hot');
  149.                }
  150.                
  151.                // Build the normal table
  152.                if($key == 'normal') {
  153.                    $return[] = build_table($table_row, $table_row['type'], 'normal');
  154.                }
  155.            
  156.             }
  157.          
  158.          }
  159.      
  160.       }
  161.  
  162.       $return[] = tab(4) . '</div>';
  163.       $return[] = tab(3) . '</td>';
  164.  
  165.    }
  166.    
  167.    // Join and return the output
  168.    return implode(hs(), $return);
  169.    
  170. }
  171.          
  172. // Set SQL Query
  173. $query = "
  174.    SELECT `machine`.`name`, `bits`.*
  175.    FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
  176. ";
  177.  
  178. // Execute
  179. $results_key = $db->execute($query);
  180.  
  181. // Make the arrays to hold the table info
  182. $table      = array();
  183. $table_keys = array();
  184.  
  185. // Loop the results
  186. while($row = $db->get_row($results_key)) {
  187.    
  188.    // Set the table header
  189.    $table_keys[] = $row['name'];
  190.    
  191.    // Check to see if this bit is on the machine.
  192.    $on_machine = ($row['onmachine']) ? 'yes' : 'no';
  193.    
  194.    // Sort by temperature starting with ultrahot
  195.    if($row['ultrahot']) {
  196.       $table[$row['name']][$on_machine]['ultrahot'] = $row;
  197.    } else if($row['hot']) {
  198.       $table[$row['name']][$on_machine]['hot'] = $row;
  199.    } else {
  200.       $table[$row['name']][$on_machine]['normal'] = $row;
  201.    }
  202.    
  203. }
  204.  
  205. ?>
  206.  
  207. <div style="overflow:auto; width:100%; height:100%">
  208.    <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  209.       <tr>
  210.          <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  211.       </tr>
  212.       <tr>
  213. <?php echo build_row($table_keys, $table, 'yes'); ?>
  214.       </tr>
  215.       <tr>
  216. <?php echo build_row($table_keys, $table, 'no'); ?>
  217.       </tr>
  218.    </table>
  219. </div>
  220.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

Thanks. Something that i am noticing is macbit. what is that?
Also how are you classifying the "hot" status. are you doing it like Bogey said?
How did you structure your DB compared to mine?
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Macbit is the name of my database I made. It is currently structured the way you have it for the hot. I structured it as close I could to your db
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

So how do you have each colum under the bits table?

im just trying to figure out how to make this fit my tables/colums

PHP Code: [ Select ]
// Set SQL Query
$query = "
  SELECT `machine`.`name`, `bits`.*
  FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
";
 
  1. // Set SQL Query
  2. $query = "
  3.   SELECT `machine`.`name`, `bits`.*
  4.   FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
  5. ";
  6.  
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

I copied your example but I think I forgot the size and I used an _ for a spice in load wk .... I am away from my computer I'm using my phone and memory to answer you're questions
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

ScottG wrote:
I copied your example but I think I forgot the size and I used an _ for a spice in load wk .... I am away from my computer I'm using my phone and memory to answer you're questions


well let me know once you get back to your computer.

side note
Why the heck aint this working
Code: [ Select ]
UPDATE bits SET serial = 'T70401193666', crown = 'T588X20316', type = 'HYBRID', size = '18.125', status = 'Mazak 650', load-wk = '14', hot = '0', ultrahot = '0', bitdate = '18-May' WHERE id = '103'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'load-wk = '14', hot = '0', ultrahot = '0', bitdate = '18-May' WHERE id = '103'' at line 1
  1. UPDATE bits SET serial = 'T70401193666', crown = 'T588X20316', type = 'HYBRID', size = '18.125', status = 'Mazak 650', load-wk = '14', hot = '0', ultrahot = '0', bitdate = '18-May' WHERE id = '103'
  2. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'load-wk = '14', hot = '0', ultrahot = '0', bitdate = '18-May' WHERE id = '103'' at line 1
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

demonmaestro wrote:
The next table is: bits
Image

The problem resides in load-wk it's actually load wk
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

i changed it in the db to load-wk and still no work.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

Ok, it's the '-'. That is not allowed in SQL syntax (though phpMyAdmin allows it for some reason). I'd recommend either using an underscore '_' or combining the words 'loadWk'.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

Bogey wrote:
Ok, it's the '-'. That is not allowed in SQL syntax (though phpMyAdmin allows it for some reason). I'd recommend either using an underscore '_' or combining the words 'loadWk'.



Thanks Bogey that worked. Now I just need to figure out how to put in the coding that ScottG posted.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

ScottG wrote:
PHP Code: [ Select ]
<?php
 
// Initialize
require_once('classes/initialize.php');
 
// These are functions to help make the code nicer and easier to read and by all means not required
// This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
function tab($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\t", $number);
   
}
 
// This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
function hs($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\r\n", $number);
   
}
 
// This function will build a string with a certain number of repeats. Example \r\n\r\n
function repeat_string($type, $number = 1) {
   
   // Make a return var
   $return = array();
   
   // Loop the number
   for($i=0; $i < $number; $i++) {
     
      // Add the tab
      $return[] = $type;
     
   }
   
   // Return the hard space
   return implode('', $return);
   
}
 
// This function is a pretty vardump
function pd($input) {
   echo '<pre>'; var_dump($input); echo '</pre>';  
}
// The functions above are to help make the code nicer and easier to read and by all means not required.
 
 
 
// This function will build out the inner table for all cases
function build_table($row, $type, $temp) {
   
   // Crrate an array to hold the table
   $return = array();
   
   // Setup the surrounding div tag to properly color the table
   switch($type) {
      case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
      case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
      case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
      case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      default :      $return[] = tab(5) .'<div>';
   }
   
   // Start building the output
   $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
   $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
   $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
   
   // Take their temperature and add to the output if their temperature matches
   switch($temp) {
      case 'ultrahot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
         
      case 'hot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
   }
   
   // Finish building the output
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(8) .'</table>';
   $return[] = tab(7) .'</div>';
   $return[] = tab(6) .'</a>';
   $return[] = tab(5) .'</div>';
   
   // Join and return the output
   return implode(hs(), $return);
   
}
 
// This function will build and return the table row
function build_row($keys, $rows, $type) {
   
   // Add return array we must.
   $return = array();
   
   // What type it is do we know. Hmmmm, yes.
   switch($type) {
      case 'yes': $text = 'In Machine'; break;
      case 'no': $text = 'Machine Que'; break;
   }
   
   // Loop through the table keys to build the columns
   foreach($keys as $value) {
     
      // Start the output
      $return[] = tab(3) . '<td align="center">';
      $return[] = tab(4) . $text;
      $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
     
      // Make sure we have an array
      if(is_array($rows[$value][$type])) {
     
         // Loop through the values that are in the on machine row of the table
         foreach($rows[$value][$type] as $key => $table_row) {
           
            // Check for NULL
            if($table_row['status']) {
           
               // Build the ultra hot table
               if($key == 'ultrahot') {
                  $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
               }
               // Build the hot table
               if($key == 'hot') {
                   $return[] = build_table($table_row, $table_row['type'], 'hot');
               }
               
               // Build the normal table
               if($key == 'normal') {
                   $return[] = build_table($table_row, $table_row['type'], 'normal');
               }
           
            }
         
         }
     
      }
 
      $return[] = tab(4) . '</div>';
      $return[] = tab(3) . '</td>';
 
   }
   
   // Join and return the output
   return implode(hs(), $return);
   
}
         
// Set SQL Query
$query = "
   SELECT `machine`.`name`, `bits`.*
   FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
";
 
// Execute
$results_key = $db->execute($query);
 
// Make the arrays to hold the table info
$table      = array();
$table_keys = array();
 
// Loop the results
while($row = $db->get_row($results_key)) {
   
   // Set the table header
   $table_keys[] = $row['name'];
   
   // Check to see if this bit is on the machine.
   $on_machine = ($row['onmachine']) ? 'yes' : 'no';
   
   // Sort by temperature starting with ultrahot
   if($row['ultrahot']) {
      $table[$row['name']][$on_machine]['ultrahot'] = $row;
   } else if($row['hot']) {
      $table[$row['name']][$on_machine]['hot'] = $row;
   } else {
      $table[$row['name']][$on_machine]['normal'] = $row;
   }
   
}
 
?>
 
<div style="overflow:auto; width:100%; height:100%">
   <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
      <tr>
         <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, 'yes'); ?>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, 'no'); ?>
      </tr>
   </table>
</div>
 
  1. <?php
  2.  
  3. // Initialize
  4. require_once('classes/initialize.php');
  5.  
  6. // These are functions to help make the code nicer and easier to read and by all means not required
  7. // This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
  8. function tab($number = 1) {
  9.    
  10.    // Call repeat_string and return the tabs
  11.    return repeat_string("\t", $number);
  12.    
  13. }
  14.  
  15. // This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
  16. function hs($number = 1) {
  17.    
  18.    // Call repeat_string and return the tabs
  19.    return repeat_string("\r\n", $number);
  20.    
  21. }
  22.  
  23. // This function will build a string with a certain number of repeats. Example \r\n\r\n
  24. function repeat_string($type, $number = 1) {
  25.    
  26.    // Make a return var
  27.    $return = array();
  28.    
  29.    // Loop the number
  30.    for($i=0; $i < $number; $i++) {
  31.      
  32.       // Add the tab
  33.       $return[] = $type;
  34.      
  35.    }
  36.    
  37.    // Return the hard space
  38.    return implode('', $return);
  39.    
  40. }
  41.  
  42. // This function is a pretty vardump
  43. function pd($input) {
  44.    echo '<pre>'; var_dump($input); echo '</pre>';  
  45. }
  46. // The functions above are to help make the code nicer and easier to read and by all means not required.
  47.  
  48.  
  49.  
  50. // This function will build out the inner table for all cases
  51. function build_table($row, $type, $temp) {
  52.    
  53.    // Crrate an array to hold the table
  54.    $return = array();
  55.    
  56.    // Setup the surrounding div tag to properly color the table
  57.    switch($type) {
  58.       case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
  59.       case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
  60.       case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  61.       case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  62.       case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  63.       case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
  64.       case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  65.       case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  66.       default :      $return[] = tab(5) .'<div>';
  67.    }
  68.    
  69.    // Start building the output
  70.    $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
  71.    $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
  72.    $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
  73.    
  74.    // Take their temperature and add to the output if their temperature matches
  75.    switch($temp) {
  76.       case 'ultrahot':
  77.          $return[] = tab(9) .'<tr>';
  78.          $return[] = tab(10) .'<td>';
  79.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
  80.          $return[] = tab(10) .'</td>';
  81.          $return[] = tab(9) .'</tr>';
  82.          break;
  83.          
  84.       case 'hot':
  85.          $return[] = tab(9) .'<tr>';
  86.          $return[] = tab(10) .'<td>';
  87.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
  88.          $return[] = tab(10) .'</td>';
  89.          $return[] = tab(9) .'</tr>';
  90.          break;
  91.    }
  92.    
  93.    // Finish building the output
  94.    $return[] = tab(9) .'<tr>';
  95.    $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
  96.    $return[] = tab(9) .'</tr>';
  97.    $return[] = tab(9) .'<tr>';
  98.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
  99.    $return[] = tab(9) .'</tr>';
  100.    $return[] = tab(9) .'<tr>';
  101.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
  102.    $return[] = tab(9) .'</tr>';
  103.    $return[] = tab(8) .'</table>';
  104.    $return[] = tab(7) .'</div>';
  105.    $return[] = tab(6) .'</a>';
  106.    $return[] = tab(5) .'</div>';
  107.    
  108.    // Join and return the output
  109.    return implode(hs(), $return);
  110.    
  111. }
  112.  
  113. // This function will build and return the table row
  114. function build_row($keys, $rows, $type) {
  115.    
  116.    // Add return array we must.
  117.    $return = array();
  118.    
  119.    // What type it is do we know. Hmmmm, yes.
  120.    switch($type) {
  121.       case 'yes': $text = 'In Machine'; break;
  122.       case 'no': $text = 'Machine Que'; break;
  123.    }
  124.    
  125.    // Loop through the table keys to build the columns
  126.    foreach($keys as $value) {
  127.      
  128.       // Start the output
  129.       $return[] = tab(3) . '<td align="center">';
  130.       $return[] = tab(4) . $text;
  131.       $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
  132.      
  133.       // Make sure we have an array
  134.       if(is_array($rows[$value][$type])) {
  135.      
  136.          // Loop through the values that are in the on machine row of the table
  137.          foreach($rows[$value][$type] as $key => $table_row) {
  138.            
  139.             // Check for NULL
  140.             if($table_row['status']) {
  141.            
  142.                // Build the ultra hot table
  143.                if($key == 'ultrahot') {
  144.                   $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
  145.                }
  146.                // Build the hot table
  147.                if($key == 'hot') {
  148.                    $return[] = build_table($table_row, $table_row['type'], 'hot');
  149.                }
  150.                
  151.                // Build the normal table
  152.                if($key == 'normal') {
  153.                    $return[] = build_table($table_row, $table_row['type'], 'normal');
  154.                }
  155.            
  156.             }
  157.          
  158.          }
  159.      
  160.       }
  161.  
  162.       $return[] = tab(4) . '</div>';
  163.       $return[] = tab(3) . '</td>';
  164.  
  165.    }
  166.    
  167.    // Join and return the output
  168.    return implode(hs(), $return);
  169.    
  170. }
  171.          
  172. // Set SQL Query
  173. $query = "
  174.    SELECT `machine`.`name`, `bits`.*
  175.    FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
  176. ";
  177.  
  178. // Execute
  179. $results_key = $db->execute($query);
  180.  
  181. // Make the arrays to hold the table info
  182. $table      = array();
  183. $table_keys = array();
  184.  
  185. // Loop the results
  186. while($row = $db->get_row($results_key)) {
  187.    
  188.    // Set the table header
  189.    $table_keys[] = $row['name'];
  190.    
  191.    // Check to see if this bit is on the machine.
  192.    $on_machine = ($row['onmachine']) ? 'yes' : 'no';
  193.    
  194.    // Sort by temperature starting with ultrahot
  195.    if($row['ultrahot']) {
  196.       $table[$row['name']][$on_machine]['ultrahot'] = $row;
  197.    } else if($row['hot']) {
  198.       $table[$row['name']][$on_machine]['hot'] = $row;
  199.    } else {
  200.       $table[$row['name']][$on_machine]['normal'] = $row;
  201.    }
  202.    
  203. }
  204.  
  205. ?>
  206.  
  207. <div style="overflow:auto; width:100%; height:100%">
  208.    <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  209.       <tr>
  210.          <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  211.       </tr>
  212.       <tr>
  213. <?php echo build_row($table_keys, $table, 'yes'); ?>
  214.       </tr>
  215.       <tr>
  216. <?php echo build_row($table_keys, $table, 'no'); ?>
  217.       </tr>
  218.    </table>
  219. </div>
  220.  


So for me yes/no is 1/0
if i understand the JOIN sql command correctly.
This is what you have.
PHP Code: [ Select ]
$query = "
  SELECT `machine`.`name`, `bits`.*
  FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
";
 
  1. $query = "
  2.   SELECT `machine`.`name`, `bits`.*
  3.   FROM `macbit`.`machine` LEFT JOIN `macbit`.`bits` ON `machine`.`name` = `bits`.`status`
  4. ";
  5.  

This is what it would look like for me?
PHP Code: [ Select ]
$query = " SELECT 'BitMachine'.'machine', 'bits'.* FROM 'BitMachine' LEFT JOIN 'bits' ON 'BitMachine'.'machine' = 'bits'.'status'";
 
  1. $query = " SELECT 'BitMachine'.'machine', 'bits'.* FROM 'BitMachine' LEFT JOIN 'bits' ON 'BitMachine'.'machine' = 'bits'.'status'";
  2.  


here is the whole code that I have edited
PHP Code: [ Select ]
<?php
 
// Initialize
require_once('data.php');
 
// These are functions to help make the code nicer and easier to read and by all means not required
// This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
function tab($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\t", $number);
   
}
 
// This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
function hs($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\r\n", $number);
   
}
 
// This function will build a string with a certain number of repeats. Example \r\n\r\n
function repeat_string($type, $number = 1) {
   
   // Make a return var
   $return = array();
   
   // Loop the number
   for($i=0; $i < $number; $i++) {
     
      // Add the tab
      $return[] = $type;
     
   }
   
   // Return the hard space
   return implode('', $return);
   
}
 
// This function is a pretty vardump
function pd($input) {
   echo '<pre>'; var_dump($input); echo '</pre>';  
}
// The functions above are to help make the code nicer and easier to read and by all means not required.
 
 
 
// This function will build out the inner table for all cases
function build_table($row, $type, $temp) {
   
   // Crrate an array to hold the table
   $return = array();
   
   // Setup the surrounding div tag to properly color the table
   switch($type) {
      case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
      case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
      case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
      case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      default :      $return[] = tab(5) .'<div>';
   }
   
   // Start building the output
   $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
   $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
   $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
   
   // Take their temperature and add to the output if their temperature matches
   switch($temp) {
      case 'ultrahot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
         
      case 'hot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
   }
   
   // Finish building the output
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(8) .'</table>';
   $return[] = tab(7) .'</div>';
   $return[] = tab(6) .'</a>';
   $return[] = tab(5) .'</div>';
   
   // Join and return the output
   return implode(hs(), $return);
   
}
 
// This function will build and return the table row
function build_row($keys, $rows, $type) {
   
   // Add return array we must.
   $return = array();
   
   // What type it is do we know. Hmmmm, yes.
   switch($type) {
      case '1': $text = 'In Machine'; break;
      case '0': $text = 'Machine Que'; break;
   }
   
   // Loop through the table keys to build the columns
   foreach($keys as $value) {
     
      // Start the output
      $return[] = tab(3) . '<td align="center">';
      $return[] = tab(4) . $text;
      $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
     
      // Make sure we have an array
      if(is_array($rows[$value][$type])) {
     
         // Loop through the values that are in the on machine row of the table
         foreach($rows[$value][$type] as $key => $table_row) {
           
            // Check for NULL
            if($table_row['status']) {
           
               // Build the ultra hot table
               if($key == 'ultrahot') {
                  $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
               }
               // Build the hot table
               if($key == 'hot') {
                   $return[] = build_table($table_row, $table_row['type'], 'hot');
               }
               
               // Build the normal table
               if($key == 'normal') {
                   $return[] = build_table($table_row, $table_row['type'], 'normal');
               }
           
            }
         
         }
     
      }
 
      $return[] = tab(4) . '</div>';
      $return[] = tab(3) . '</td>';
 
   }
   
   // Join and return the output
   return implode(hs(), $return);
   
}
         
// Set SQL Query
$query = " SELECT 'BitMachine'.'machine', 'bits'.* FROM 'BitMachine' LEFT JOIN 'bits' ON 'BitMachine'.'machine' = 'bits'.'status'";
 
// Execute
$results_key = $db->execute($query);
 
// Make the arrays to hold the table info
$table      = array();
$table_keys = array();
 
// Loop the results
while($row = $db->get_row($results_key)) {
   
   // Set the table header
   $table_keys[] = $row['name'];
   
   // Check to see if this bit is on the machine.
   $on_machine = ($row['onmachine']) ? '1' : '0';
   
   // Sort by temperature starting with ultrahot
   if($row['ultrahot']) {
      $table[$row['name']][$on_machine]['ultrahot'] = $row;
   } else if($row['hot']) {
      $table[$row['name']][$on_machine]['hot'] = $row;
   } else {
      $table[$row['name']][$on_machine]['normal'] = $row;
   }
   
}
 
?>
 
<div style="overflow:auto; width:100%; height:100%">
   <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
      <tr>
         <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, '1'); ?>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, '0'); ?>
      </tr>
   </table>
</div>
 
  1. <?php
  2.  
  3. // Initialize
  4. require_once('data.php');
  5.  
  6. // These are functions to help make the code nicer and easier to read and by all means not required
  7. // This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
  8. function tab($number = 1) {
  9.    
  10.    // Call repeat_string and return the tabs
  11.    return repeat_string("\t", $number);
  12.    
  13. }
  14.  
  15. // This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
  16. function hs($number = 1) {
  17.    
  18.    // Call repeat_string and return the tabs
  19.    return repeat_string("\r\n", $number);
  20.    
  21. }
  22.  
  23. // This function will build a string with a certain number of repeats. Example \r\n\r\n
  24. function repeat_string($type, $number = 1) {
  25.    
  26.    // Make a return var
  27.    $return = array();
  28.    
  29.    // Loop the number
  30.    for($i=0; $i < $number; $i++) {
  31.      
  32.       // Add the tab
  33.       $return[] = $type;
  34.      
  35.    }
  36.    
  37.    // Return the hard space
  38.    return implode('', $return);
  39.    
  40. }
  41.  
  42. // This function is a pretty vardump
  43. function pd($input) {
  44.    echo '<pre>'; var_dump($input); echo '</pre>';  
  45. }
  46. // The functions above are to help make the code nicer and easier to read and by all means not required.
  47.  
  48.  
  49.  
  50. // This function will build out the inner table for all cases
  51. function build_table($row, $type, $temp) {
  52.    
  53.    // Crrate an array to hold the table
  54.    $return = array();
  55.    
  56.    // Setup the surrounding div tag to properly color the table
  57.    switch($type) {
  58.       case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
  59.       case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
  60.       case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  61.       case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  62.       case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  63.       case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
  64.       case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  65.       case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  66.       default :      $return[] = tab(5) .'<div>';
  67.    }
  68.    
  69.    // Start building the output
  70.    $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
  71.    $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
  72.    $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
  73.    
  74.    // Take their temperature and add to the output if their temperature matches
  75.    switch($temp) {
  76.       case 'ultrahot':
  77.          $return[] = tab(9) .'<tr>';
  78.          $return[] = tab(10) .'<td>';
  79.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
  80.          $return[] = tab(10) .'</td>';
  81.          $return[] = tab(9) .'</tr>';
  82.          break;
  83.          
  84.       case 'hot':
  85.          $return[] = tab(9) .'<tr>';
  86.          $return[] = tab(10) .'<td>';
  87.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
  88.          $return[] = tab(10) .'</td>';
  89.          $return[] = tab(9) .'</tr>';
  90.          break;
  91.    }
  92.    
  93.    // Finish building the output
  94.    $return[] = tab(9) .'<tr>';
  95.    $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
  96.    $return[] = tab(9) .'</tr>';
  97.    $return[] = tab(9) .'<tr>';
  98.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
  99.    $return[] = tab(9) .'</tr>';
  100.    $return[] = tab(9) .'<tr>';
  101.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
  102.    $return[] = tab(9) .'</tr>';
  103.    $return[] = tab(8) .'</table>';
  104.    $return[] = tab(7) .'</div>';
  105.    $return[] = tab(6) .'</a>';
  106.    $return[] = tab(5) .'</div>';
  107.    
  108.    // Join and return the output
  109.    return implode(hs(), $return);
  110.    
  111. }
  112.  
  113. // This function will build and return the table row
  114. function build_row($keys, $rows, $type) {
  115.    
  116.    // Add return array we must.
  117.    $return = array();
  118.    
  119.    // What type it is do we know. Hmmmm, yes.
  120.    switch($type) {
  121.       case '1': $text = 'In Machine'; break;
  122.       case '0': $text = 'Machine Que'; break;
  123.    }
  124.    
  125.    // Loop through the table keys to build the columns
  126.    foreach($keys as $value) {
  127.      
  128.       // Start the output
  129.       $return[] = tab(3) . '<td align="center">';
  130.       $return[] = tab(4) . $text;
  131.       $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
  132.      
  133.       // Make sure we have an array
  134.       if(is_array($rows[$value][$type])) {
  135.      
  136.          // Loop through the values that are in the on machine row of the table
  137.          foreach($rows[$value][$type] as $key => $table_row) {
  138.            
  139.             // Check for NULL
  140.             if($table_row['status']) {
  141.            
  142.                // Build the ultra hot table
  143.                if($key == 'ultrahot') {
  144.                   $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
  145.                }
  146.                // Build the hot table
  147.                if($key == 'hot') {
  148.                    $return[] = build_table($table_row, $table_row['type'], 'hot');
  149.                }
  150.                
  151.                // Build the normal table
  152.                if($key == 'normal') {
  153.                    $return[] = build_table($table_row, $table_row['type'], 'normal');
  154.                }
  155.            
  156.             }
  157.          
  158.          }
  159.      
  160.       }
  161.  
  162.       $return[] = tab(4) . '</div>';
  163.       $return[] = tab(3) . '</td>';
  164.  
  165.    }
  166.    
  167.    // Join and return the output
  168.    return implode(hs(), $return);
  169.    
  170. }
  171.          
  172. // Set SQL Query
  173. $query = " SELECT 'BitMachine'.'machine', 'bits'.* FROM 'BitMachine' LEFT JOIN 'bits' ON 'BitMachine'.'machine' = 'bits'.'status'";
  174.  
  175. // Execute
  176. $results_key = $db->execute($query);
  177.  
  178. // Make the arrays to hold the table info
  179. $table      = array();
  180. $table_keys = array();
  181.  
  182. // Loop the results
  183. while($row = $db->get_row($results_key)) {
  184.    
  185.    // Set the table header
  186.    $table_keys[] = $row['name'];
  187.    
  188.    // Check to see if this bit is on the machine.
  189.    $on_machine = ($row['onmachine']) ? '1' : '0';
  190.    
  191.    // Sort by temperature starting with ultrahot
  192.    if($row['ultrahot']) {
  193.       $table[$row['name']][$on_machine]['ultrahot'] = $row;
  194.    } else if($row['hot']) {
  195.       $table[$row['name']][$on_machine]['hot'] = $row;
  196.    } else {
  197.       $table[$row['name']][$on_machine]['normal'] = $row;
  198.    }
  199.    
  200. }
  201.  
  202. ?>
  203.  
  204. <div style="overflow:auto; width:100%; height:100%">
  205.    <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  206.       <tr>
  207.          <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  208.       </tr>
  209.       <tr>
  210. <?php echo build_row($table_keys, $table, '1'); ?>
  211.       </tr>
  212.       <tr>
  213. <?php echo build_row($table_keys, $table, '0'); ?>
  214.       </tr>
  215.    </table>
  216. </div>
  217.  


This is how my bits table currently looks like..
Although "load wk" now looks like this: "load_wk"
Image
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

The SQL looks correct but the execution of it seem to be my db class calls still

line 176 in the code you posted (based on your previous posts) should be
PHP Code: [ Select ]
$results_key = mysql_query($query);
 
  1. $results_key = mysql_query($query);
  2.  


and line 183 should be
PHP Code: [ Select ]
while($row = mysql_fetch_array($results_key)) {
 
  1. while($row = mysql_fetch_array($results_key)) {
  2.  


OR if you do use a DB class what ever your SQL exec function is and whatever your row return function is.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

I changed it and i am getting this
Quote:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in temp2.php on line 183

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

That most likely means that the query (line 173-176) failed and is giving back false instead of the needed resource. You should check the SQL and make sure it fits your database tables and fields properly.

You could change line 176 for the following to get a better understanding on what's failing:.
PHP Code: [ Select ]
$results_key = mysql_query($query) or die(mysql_error());
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.'machine', 'bits'.* FROM 'BitMachine' LEFT JOIN 'bits' ON 'BitMachine'.'machine' at line 1
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

I'm not sure about this, but try this query instead of what you got. (I think it's a case of misplaced ` (slanted apostrophe)). (I'm also not sure if the asterisk (*) needs the apostrophes (`*`)).
SQL Code: [ Select ]
SELECT `BitMachine`.`machine`, `bits`.*
FROM `BitMachine`
LEFT JOIN `bits`
ON `BitMachine`.`machine` = `bits`.`status`
  1. SELECT `BitMachine`.`machine`, `bits`.*
  2. FROM `BitMachine`
  3. LEFT JOIN `bits`
  4. ON `BitMachine`.`machine` = `bits`.`status`

Or if that fails try the same query without the apostrophes. (STATUS should be status (not capitalized)).
SQL Code: [ Select ]
SELECT BitMachine.machine, bits.*
FROM BitMachine
LEFT JOIN bits
ON BitMachine.machine = bits.STATUS
  1. SELECT BitMachine.machine, bits.*
  2. FROM BitMachine
  3. LEFT JOIN bits
  4. ON BitMachine.machine = bits.STATUS
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

Well i took out the (') and it showing up now.

However now it is showing a new colum for each pending bit
PHP Code: [ Select ]
<?php
 
// Initialize
require_once('data.php');
 
// These are functions to help make the code nicer and easier to read and by all means not required
// This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
function tab($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\t", $number);
   
}
 
// This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
function hs($number = 1) {
   
   // Call repeat_string and return the tabs
   return repeat_string("\r\n", $number);
   
}
 
// This function will build a string with a certain number of repeats. Example \r\n\r\n
function repeat_string($type, $number = 1) {
   
   // Make a return var
   $return = array();
   
   // Loop the number
   for($i=0; $i < $number; $i++) {
     
      // Add the tab
      $return[] = $type;
     
   }
   
   // Return the hard space
   return implode('', $return);
   
}
 
// This function is a pretty vardump
function pd($input) {
   echo '<pre>'; var_dump($input); echo '</pre>';  
}
// The functions above are to help make the code nicer and easier to read and by all means not required.
 
 
 
// This function will build out the inner table for all cases
function build_table($row, $type, $temp) {
   
   // Crrate an array to hold the table
   $return = array();
   
   // Setup the surrounding div tag to properly color the table
   switch($type) {
      case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
      case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
      case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
      case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
      case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
      default :      $return[] = tab(5) .'<div>';
   }
   
   // Start building the output
   $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
   $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
   $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
   
   // Take their temperature and add to the output if their temperature matches
   switch($temp) {
      case 'ultrahot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
         
      case 'hot':
         $return[] = tab(9) .'<tr>';
         $return[] = tab(10) .'<td>';
         $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
         $return[] = tab(10) .'</td>';
         $return[] = tab(9) .'</tr>';
         break;
   }
   
   // Finish building the output
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(9) .'<tr>';
   $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
   $return[] = tab(9) .'</tr>';
   $return[] = tab(8) .'</table>';
   $return[] = tab(7) .'</div>';
   $return[] = tab(6) .'</a>';
   $return[] = tab(5) .'</div>';
   
   // Join and return the output
   return implode(hs(), $return);
   
}
 
// This function will build and return the table row
function build_row($keys, $rows, $type) {
   
   // Add return array we must.
   $return = array();
   
   // What type it is do we know. Hmmmm, yes.
   switch($type) {
      case '1': $text = 'In Machine'; break;
      case '0': $text = 'Machine Que'; break;
   }
   
   // Loop through the table keys to build the columns
   foreach($keys as $value) {
     
      // Start the output
      $return[] = tab(3) . '<td align="center">';
      $return[] = tab(4) . $text;
      $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
     
      // Make sure we have an array
      if(is_array($rows[$value][$type])) {
     
         // Loop through the values that are in the on machine row of the table
         foreach($rows[$value][$type] as $key => $table_row) {
           
            // Check for NULL
            if($table_row['status']) {
           
               // Build the ultra hot table
               if($key == 'ultrahot') {
                  $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
               }
               // Build the hot table
               if($key == 'hot') {
                   $return[] = build_table($table_row, $table_row['type'], 'hot');
               }
               
               // Build the normal table
               if($key == 'status') {
                   $return[] = build_table($table_row, $table_row['type'], 'status');
               }
           
            }
         
         } 
     
      }
 
      $return[] = tab(4) . '</div>';
      $return[] = tab(3) . '</td>';
 
   }
   
   // Join and return the output
   return implode(hs(), $return);
   
}
         
// Set SQL Query
$query = "SELECT BitMachine.machine, bits.* FROM BitMachine LEFT JOIN bits ON BitMachine.machine = bits.status";
 
// Execute
$results_key = mysql_query($query) or die(mysql_error());
 
// Make the arrays to hold the table info
$table      = array();
$table_keys = array();
 
// Loop the results
while($row = mysql_fetch_array($results_key)) {
   
   // Set the table header
   $table_keys[] = $row['machine'];
   
   // Check to see if this bit is on the machine.
   $on_machine = ($row['onmachine']) ? '1' : '0';
   
   // Sort by temperature starting with ultrahot
   if($row['ultrahot']) {
      $table[$row['machine']][$on_machine]['ultrahot'] = $row;
   } else if($row['hot']) {
      $table[$row['machine']][$on_machine]['hot'] = $row;
   } else {
      $table[$row['machine']][$on_machine]['status'] = $row;
   }
   
}
 
?>
 
<div style="overflow:auto; width:100%; height:100%">
   <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
      <tr>
         <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, '1'); ?>
      </tr>
      <tr>
<?php echo build_row($table_keys, $table, '0'); ?>
      </tr>
   </table>
</div>
 
  1. <?php
  2.  
  3. // Initialize
  4. require_once('data.php');
  5.  
  6. // These are functions to help make the code nicer and easier to read and by all means not required
  7. // This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
  8. function tab($number = 1) {
  9.    
  10.    // Call repeat_string and return the tabs
  11.    return repeat_string("\t", $number);
  12.    
  13. }
  14.  
  15. // This function is just to make code pretty and returns hard spaces '\r\n'. This function relies on the repeat_string function
  16. function hs($number = 1) {
  17.    
  18.    // Call repeat_string and return the tabs
  19.    return repeat_string("\r\n", $number);
  20.    
  21. }
  22.  
  23. // This function will build a string with a certain number of repeats. Example \r\n\r\n
  24. function repeat_string($type, $number = 1) {
  25.    
  26.    // Make a return var
  27.    $return = array();
  28.    
  29.    // Loop the number
  30.    for($i=0; $i < $number; $i++) {
  31.      
  32.       // Add the tab
  33.       $return[] = $type;
  34.      
  35.    }
  36.    
  37.    // Return the hard space
  38.    return implode('', $return);
  39.    
  40. }
  41.  
  42. // This function is a pretty vardump
  43. function pd($input) {
  44.    echo '<pre>'; var_dump($input); echo '</pre>';  
  45. }
  46. // The functions above are to help make the code nicer and easier to read and by all means not required.
  47.  
  48.  
  49.  
  50. // This function will build out the inner table for all cases
  51. function build_table($row, $type, $temp) {
  52.    
  53.    // Crrate an array to hold the table
  54.    $return = array();
  55.    
  56.    // Setup the surrounding div tag to properly color the table
  57.    switch($type) {
  58.       case 'STEEL':  $return[] = tab(5) .'<div style="background-color:#FF9999;">'; break;
  59.       case 'SLIM':   $return[] = tab(5) .'<div style="background-color:#9999FF;">'; break;
  60.       case 'KYMERA':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  61.       case 'HYBRID':    $return[] = tab(5) .'<div style="background-color:#FF2626;">'; break;
  62.       case 'EZC':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  63.       case 'RWD':    $return[] = tab(5) .'<div style="background-color:#FF9326;">'; break;
  64.       case 'EZR':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  65.       case 'EZB':    $return[] = tab(5) .'<div style="background-color:#FFFF26;">'; break;
  66.       default :      $return[] = tab(5) .'<div>';
  67.    }
  68.    
  69.    // Start building the output
  70.    $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
  71.    $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
  72.    $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
  73.    
  74.    // Take their temperature and add to the output if their temperature matches
  75.    switch($temp) {
  76.       case 'ultrahot':
  77.          $return[] = tab(9) .'<tr>';
  78.          $return[] = tab(10) .'<td>';
  79.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
  80.          $return[] = tab(10) .'</td>';
  81.          $return[] = tab(9) .'</tr>';
  82.          break;
  83.          
  84.       case 'hot':
  85.          $return[] = tab(9) .'<tr>';
  86.          $return[] = tab(10) .'<td>';
  87.          $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
  88.          $return[] = tab(10) .'</td>';
  89.          $return[] = tab(9) .'</tr>';
  90.          break;
  91.    }
  92.    
  93.    // Finish building the output
  94.    $return[] = tab(9) .'<tr>';
  95.    $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load_wk'] .'</a></td>';
  96.    $return[] = tab(9) .'</tr>';
  97.    $return[] = tab(9) .'<tr>';
  98.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
  99.    $return[] = tab(9) .'</tr>';
  100.    $return[] = tab(9) .'<tr>';
  101.    $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
  102.    $return[] = tab(9) .'</tr>';
  103.    $return[] = tab(8) .'</table>';
  104.    $return[] = tab(7) .'</div>';
  105.    $return[] = tab(6) .'</a>';
  106.    $return[] = tab(5) .'</div>';
  107.    
  108.    // Join and return the output
  109.    return implode(hs(), $return);
  110.    
  111. }
  112.  
  113. // This function will build and return the table row
  114. function build_row($keys, $rows, $type) {
  115.    
  116.    // Add return array we must.
  117.    $return = array();
  118.    
  119.    // What type it is do we know. Hmmmm, yes.
  120.    switch($type) {
  121.       case '1': $text = 'In Machine'; break;
  122.       case '0': $text = 'Machine Que'; break;
  123.    }
  124.    
  125.    // Loop through the table keys to build the columns
  126.    foreach($keys as $value) {
  127.      
  128.       // Start the output
  129.       $return[] = tab(3) . '<td align="center">';
  130.       $return[] = tab(4) . $text;
  131.       $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
  132.      
  133.       // Make sure we have an array
  134.       if(is_array($rows[$value][$type])) {
  135.      
  136.          // Loop through the values that are in the on machine row of the table
  137.          foreach($rows[$value][$type] as $key => $table_row) {
  138.            
  139.             // Check for NULL
  140.             if($table_row['status']) {
  141.            
  142.                // Build the ultra hot table
  143.                if($key == 'ultrahot') {
  144.                   $return[] = build_table($table_row, $table_row['type'], 'ultrahot');
  145.                }
  146.                // Build the hot table
  147.                if($key == 'hot') {
  148.                    $return[] = build_table($table_row, $table_row['type'], 'hot');
  149.                }
  150.                
  151.                // Build the normal table
  152.                if($key == 'status') {
  153.                    $return[] = build_table($table_row, $table_row['type'], 'status');
  154.                }
  155.            
  156.             }
  157.          
  158.          } 
  159.      
  160.       }
  161.  
  162.       $return[] = tab(4) . '</div>';
  163.       $return[] = tab(3) . '</td>';
  164.  
  165.    }
  166.    
  167.    // Join and return the output
  168.    return implode(hs(), $return);
  169.    
  170. }
  171.          
  172. // Set SQL Query
  173. $query = "SELECT BitMachine.machine, bits.* FROM BitMachine LEFT JOIN bits ON BitMachine.machine = bits.status";
  174.  
  175. // Execute
  176. $results_key = mysql_query($query) or die(mysql_error());
  177.  
  178. // Make the arrays to hold the table info
  179. $table      = array();
  180. $table_keys = array();
  181.  
  182. // Loop the results
  183. while($row = mysql_fetch_array($results_key)) {
  184.    
  185.    // Set the table header
  186.    $table_keys[] = $row['machine'];
  187.    
  188.    // Check to see if this bit is on the machine.
  189.    $on_machine = ($row['onmachine']) ? '1' : '0';
  190.    
  191.    // Sort by temperature starting with ultrahot
  192.    if($row['ultrahot']) {
  193.       $table[$row['machine']][$on_machine]['ultrahot'] = $row;
  194.    } else if($row['hot']) {
  195.       $table[$row['machine']][$on_machine]['hot'] = $row;
  196.    } else {
  197.       $table[$row['machine']][$on_machine]['status'] = $row;
  198.    }
  199.    
  200. }
  201.  
  202. ?>
  203.  
  204. <div style="overflow:auto; width:100%; height:100%">
  205.    <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  206.       <tr>
  207.          <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  208.       </tr>
  209.       <tr>
  210. <?php echo build_row($table_keys, $table, '1'); ?>
  211.       </tr>
  212.       <tr>
  213. <?php echo build_row($table_keys, $table, '0'); ?>
  214.       </tr>
  215.    </table>
  216. </div>
  217.  


Image
Image
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

on line 207

try replacing
PHP Code: [ Select ]
<td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>

with
PHP Code: [ Select ]
<td align="center"><?php echo implode('</td><td>', array_unique($table_keys)); ?></td>
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

also i didn't catch that you used a normal apostrophe (') instead of the slanted one (`) Same key as ~

using `*` will cause an error
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

ScottG wrote:
on line 207

try replacing
PHP Code: [ Select ]
<td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>

with
PHP Code: [ Select ]
<td align="center"><?php echo implode('</td><td>', array_unique($table_keys)); ?></td>


^^^ that did nothing.

ScottG wrote:
also i didn't catch that you used a normal apostrophe (') instead of the slanted one (`) Same key as ~

using `*` will cause an error


I just took out the ' and the ` and it started to show.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

i forgot table keys gets used more than once so forget my last post and under the while loop add

PHP Code: [ Select ]
$table_keys = array_unique($table_keys);


it should look like

PHP Code: [ Select ]
// Loop the results
while($row = mysql_fetch_array($results_key)) {
   
   // Set the table header
   $table_keys[] = $row['machine'];
   
   // Check to see if this bit is on the machine.
   $on_machine = ($row['onmachine']) ? '1' : '0';
   
   // Sort by temperature starting with ultrahot
   if($row['ultrahot']) {
      $table[$row['machine']][$on_machine]['ultrahot'] = $row;
   } else if($row['hot']) {
      $table[$row['machine']][$on_machine]['hot'] = $row;
   } else {
      $table[$row['machine']][$on_machine]['status'] = $row;
   }
   
}
 
$table_keys = array_unique($table_keys);
 
  1. // Loop the results
  2. while($row = mysql_fetch_array($results_key)) {
  3.    
  4.    // Set the table header
  5.    $table_keys[] = $row['machine'];
  6.    
  7.    // Check to see if this bit is on the machine.
  8.    $on_machine = ($row['onmachine']) ? '1' : '0';
  9.    
  10.    // Sort by temperature starting with ultrahot
  11.    if($row['ultrahot']) {
  12.       $table[$row['machine']][$on_machine]['ultrahot'] = $row;
  13.    } else if($row['hot']) {
  14.       $table[$row['machine']][$on_machine]['hot'] = $row;
  15.    } else {
  16.       $table[$row['machine']][$on_machine]['status'] = $row;
  17.    }
  18.    
  19. }
  20.  
  21. $table_keys = array_unique($table_keys);
  22.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 679
  • Loc: Conroe, Texas

Post 3+ Months Ago

well that took care of the side to side thing but once i added another bit to the machine que it is not showing.

Image
Image

Post Information

  • Total Posts in this topic: 104 posts
  • Users browsing this forum: No registered users and 60 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.