php/mysql table

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

Post 3+ Months Ago

Okay I am using 2 different tables in the db to make this table

I got this table. where you see crown,profile,crown,profile,mazak 650 -> all of that is pulled from one table in the DB
while the 7037542 stuff is listed under a different table and has a row listed for a particular machine.

so how you see it it is listed like

7037542 - crown
7038561 - mazak

and each order will need to go to its correct row.

I am drawling a brain fart as to how to do the while statements on this issue.

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

Post 3+ Months Ago

PHP Code: [ Select ]
<?
$m =  "SELECT  * FROM bob";
$stored_machines = mysql_query($m);
echo"<table><tr>";
while ($mch = mysql_fetch_array($stored_machines)) {
   echo "<td>".$mch['machine']."<td>";
   $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
   while ($ord = mysql_fetch_array($stored_orders)) {
      echo "<tr><td>".$ord['serial']."</td></tr>";
   }
}
echo"</tr></table>";
  ?>
  1. <?
  2. $m =  "SELECT  * FROM bob";
  3. $stored_machines = mysql_query($m);
  4. echo"<table><tr>";
  5. while ($mch = mysql_fetch_array($stored_machines)) {
  6.    echo "<td>".$mch['machine']."<td>";
  7.    $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
  8.    while ($ord = mysql_fetch_array($stored_orders)) {
  9.       echo "<tr><td>".$ord['serial']."</td></tr>";
  10.    }
  11. }
  12. echo"</tr></table>";
  13.   ?>


It works now but the issue is it only displays the info going down. I want the $mch['machine'] to go sideways like it is in the picture above.

This is how it looks right now
Quote:
Mazak 650
T7040960
T7040963
DMG1
T7040961
6300 #2
T7040962


This is how it should look
Code: [ Select ]
Mazak 650  DMG1   6300 #2 
T7040960  T7040961 T7040962
T7040963
  1. Mazak 650  DMG1   6300 #2 
  2. T7040960  T7040961 T7040962
  3. T7040963
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

a little confusing but i think i know what your talking about.

I would use a one to many relationship join

to Pseudocode this out to see if this works for you or gives you an idea

table one I'll call brands and table two called products

in the brands table you have crown, profile, and mazak

| id | name |
|--------------|
|1 | Crown |
|2 | Profile |
|3 | Mazak |
|--------------|

in products table

| parent_id | name |
|---------------------|
|1 | 7037542 |
|3 | 7037543 |
|1 | 7037544 |
|2 | 7037545 |
|2 | 7037546 |
|2 | 7037547 |
|1 | 7037548 |
|3 | 7037549 |
|1 | 7037550 |
|3 | 7037551 |
|3 | 7037552 |
|1 | 7037553 |
|---------------------|

MYSQL Code: [ Select ]
SELECT `brands`.`name`, `products`.`name` AS `machine`
FROM `brands`, `products`
WHERE `brands`.`id` = `products`.`parent_id`
 
  1. SELECT `brands`.`name`, `products`.`name` AS `machine`
  2. FROM `brands`, `products`
  3. WHERE `brands`.`id` = `products`.`parent_id`
  4.  


output should be something like

| name | machine |
|------------------|
|Crown | 7037542 |
|Mazak | 7037543 |
|Crown | 7037544 |
|Profile | 7037545 |
|Profile | 7037546 |
|Profile | 7037547 |
|Crown | 7037548 |
|Mazak | 7037549 |
|Crown | 7037550 |
|Mazak | 7037551 |
|Mazak | 7037552 |
|Crown | 7037553 |
|------------------|

Based On what you've stated this is how i assume your result to show up as If this is correct you could then you an array or object based on what language you're using to pre build your table.

My PHP example
PHP Code: [ Select ]
<?php
 
$table = array();
$ii = 0;
 
while($row = mysql_fetch_assoc($result)) {
    $table[$ii][$row['name']][] = $row['machine'];
    $ii++;
}
 
$table_keys = array_keys($table[0]);
$ii = 0;
 
// Then build the final output ?>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php echo implode('</td><td>', $table_keys); ?></td>
  </tr>
  <?php foreach($table as $key => $table_row) { ?>
  <tr>
    <?php foreach($table_keys as $value) {
        echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
    ?>
  </tr>
  <?php $ii++; } ?>
 
  1. <?php
  2.  
  3. $table = array();
  4. $ii = 0;
  5.  
  6. while($row = mysql_fetch_assoc($result)) {
  7.     $table[$ii][$row['name']][] = $row['machine'];
  8.     $ii++;
  9. }
  10.  
  11. $table_keys = array_keys($table[0]);
  12. $ii = 0;
  13.  
  14. // Then build the final output ?>
  15. <table border="0" cellspacing="0" cellpadding="0">
  16.   <tr>
  17.     <td><?php echo implode('</td><td>', $table_keys); ?></td>
  18.   </tr>
  19.   <?php foreach($table as $key => $table_row) { ?>
  20.   <tr>
  21.     <?php foreach($table_keys as $value) {
  22.         echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
  23.     ?>
  24.   </tr>
  25.   <?php $ii++; } ?>
  26.  


PS. I just saw you added info
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

From your example get rid of the trs
PHP Code: [ Select ]
    <?
    $m =  "SELECT  * FROM bob";
    $stored_machines = mysql_query($m);
    echo"<table><tr>";
    while ($mch = mysql_fetch_array($stored_machines)) {
       echo "<td>".$mch['machine']."<td>";
       $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
       while ($ord = mysql_fetch_array($stored_orders)) {
          echo "<td>".$ord['serial']."</td>"; //////// RIGHT HERE
       }
    }
    echo"</tr></table>";
      ?>
 
  1.     <?
  2.     $m =  "SELECT  * FROM bob";
  3.     $stored_machines = mysql_query($m);
  4.     echo"<table><tr>";
  5.     while ($mch = mysql_fetch_array($stored_machines)) {
  6.        echo "<td>".$mch['machine']."<td>";
  7.        $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
  8.        while ($ord = mysql_fetch_array($stored_orders)) {
  9.           echo "<td>".$ord['serial']."</td>"; //////// RIGHT HERE
  10.        }
  11.     }
  12.     echo"</tr></table>";
  13.       ?>
  14.  


EDIT:: Never mind that won't work i just looked at the code again
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

Mix my first post in

PHP Code: [ Select ]
<?
 
$table      = array();
$table_keys = array();
$ii=0;
 
$m =  "SELECT  * FROM bob";
$stored_machines = mysql_query($m);
while ($mch = mysql_fetch_array($stored_machines)) {
    $table_keys[] = $mch['machine']
    $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
    while ($ord = mysql_fetch_array($stored_orders)) {
         
        $table[$ii][$mch['machine']][] = $ord['serial'];
 
    }
}
 
// Reset counter
$ii = 0;
 
// Then build the final output
 
?>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php echo implode('</td><td>', $table_keys); ?></td>
  </tr>
  <?php foreach($table as $key => $table_row) { ?>
  <tr>
    <?php foreach($table_keys as $value) {
        echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
    ?>
  </tr>
  <?php $ii++; } ?>
 
  1. <?
  2.  
  3. $table      = array();
  4. $table_keys = array();
  5. $ii=0;
  6.  
  7. $m =  "SELECT  * FROM bob";
  8. $stored_machines = mysql_query($m);
  9. while ($mch = mysql_fetch_array($stored_machines)) {
  10.     $table_keys[] = $mch['machine']
  11.     $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
  12.     while ($ord = mysql_fetch_array($stored_orders)) {
  13.          
  14.         $table[$ii][$mch['machine']][] = $ord['serial'];
  15.  
  16.     }
  17. }
  18.  
  19. // Reset counter
  20. $ii = 0;
  21.  
  22. // Then build the final output
  23.  
  24. ?>
  25. <table border="0" cellspacing="0" cellpadding="0">
  26.   <tr>
  27.     <td><?php echo implode('</td><td>', $table_keys); ?></td>
  28.   </tr>
  29.   <?php foreach($table as $key => $table_row) { ?>
  30.   <tr>
  31.     <?php foreach($table_keys as $value) {
  32.         echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
  33.     ?>
  34.   </tr>
  35.   <?php $ii++; } ?>
  36.  


NOT PERFECT OR TESTED but the idea/concept is there
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

I am getting this
Code: [ Select ]
Parse error: syntax error, unexpected end of file in temp2.php on line 36


|-Mazak 650-|-DMG1-----|-6300 #2--|
|-T7040960--|-T7040961-|-T7040962-|
|-T7040963--|
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

This is how i want it to look
demonmaestro wrote:
Image
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

$table_keys[] = $mch['machine']; missing ;

EDIT:: Also there is a missing }
PHP Code: [ Select ]
<?php foreach($table_keys as $value) {
        echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
   } ?> // right here
 
  1. <?php foreach($table_keys as $value) {
  2.         echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
  3.    } ?> // right here
  4.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ScottG wrote:
$table_keys[] = $mch['machine']; missing ;


Yea i found the first ; one but is there a second one i am missing? still coming up with same error,

never mind found it. Was missing a }
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Array is not array.. array has gone array.. there is data that is not showing...

Quote:

Mazak 650 DMG1 6300 #2 6300 #3
Array
Array
Array
Array
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

check the edit above also in the first while loop remove the inner array

$table[$ii][$mch['machine']][] = $ord['serial']; this to $table[$ii][$mch['machine']] = $ord['serial'];
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

The data shows but not under the correct machine.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

Could you var_dump($table); also what is the HTML output showing up as?
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

OK i think i figured it out in the database area i forgot to the add the $ii increments

PHP Code: [ Select ]
    <?
     
    $table      = array();
    $table_keys = array();
    $ii=0;
     
    $m =  "SELECT  * FROM bob";
    $stored_machines = mysql_query($m);
    while ($mch = mysql_fetch_array($stored_machines)) {
        $table_keys[] = $mch['machine']; // Fixed the ;
        $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
        while ($ord = mysql_fetch_array($stored_orders)) {
             
            $table[$ii][$mch['machine']][] = $ord['serial'];
            $ii++; // Added the $ii++
        }
        $ii=0; // Reset the counter
    }
     
    // Reset counter
    $ii = 0;
     
    // Then build the final output
     
    ?>
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <?php foreach($table as $key => $table_row) { ?>
      <tr>
        <?php foreach($table_keys as $value) {
            echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
        } // Fixed the missing }
        ?>
      </tr>
      <?php $ii++; } ?>
     
 
 
  1.     <?
  2.      
  3.     $table      = array();
  4.     $table_keys = array();
  5.     $ii=0;
  6.      
  7.     $m =  "SELECT  * FROM bob";
  8.     $stored_machines = mysql_query($m);
  9.     while ($mch = mysql_fetch_array($stored_machines)) {
  10.         $table_keys[] = $mch['machine']; // Fixed the ;
  11.         $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
  12.         while ($ord = mysql_fetch_array($stored_orders)) {
  13.              
  14.             $table[$ii][$mch['machine']][] = $ord['serial'];
  15.             $ii++; // Added the $ii++
  16.         }
  17.         $ii=0; // Reset the counter
  18.     }
  19.      
  20.     // Reset counter
  21.     $ii = 0;
  22.      
  23.     // Then build the final output
  24.      
  25.     ?>
  26.     <table border="0" cellspacing="0" cellpadding="0">
  27.       <tr>
  28.         <td><?php echo implode('</td><td>', $table_keys); ?></td>
  29.       </tr>
  30.       <?php foreach($table as $key => $table_row) { ?>
  31.       <tr>
  32.         <?php foreach($table_keys as $value) {
  33.             echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
  34.         } // Fixed the missing }
  35.         ?>
  36.       </tr>
  37.       <?php $ii++; } ?>
  38.      
  39.  
  40.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Close but no cigar. still getting "array"
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

damn lol i forgot one thing that was fixed before $table[$ii][$mch['machine']][] = $ord['serial']; this to $table[$ii][$mch['machine']] = $ord['serial'];
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Its a cluster but i can figure it out from here..
Thank you sir. You are a life saver. :bouncingsmile:
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

I'll post my test code it's different since i don't have a database but it does work the same as having a database.

PHP Code: [ Select ]
    <?php
   $db1 = array(
      array('machine' => 'Mazak 650'),
      array('machine' => 'DMG1'),
      array('machine' => '6300 #2')
      );
   
   $db2 = array(
      "Mazak 650" => array(array('serial' => 'T7040960'), array('serial' => 'T7040963')),
      "DMG1" => array(array('serial' => 'T7040961')),
      "6300 #2" => array(array('serial' => 'T7040962'))  
      );
     
    $table      = array();
    $table_keys = array();
    $ii=0;
     
 
    foreach($db1 as $mch) {
        $table_keys[] = $mch['machine'];
//var_dump($db2[$mch['machine']]);
        foreach ($db2[$mch['machine']] as $ord) {
             
            $table[$ii][$mch['machine']] = $ord['serial'];
     $ii++;
        }
      $ii=0;
    }
     
   //var_dump($table);
    // Reset counter
    $ii = 0;
     
    // Then build the final output
     
    ?>
    <table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <?php foreach($table as $key => $table_row) { ?>
      <tr>
        <?php foreach($table_keys as $value) {
            echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
      } ?>
      </tr>
      <?php $ii++; } ?>
 
 
  1.     <?php
  2.    $db1 = array(
  3.       array('machine' => 'Mazak 650'),
  4.       array('machine' => 'DMG1'),
  5.       array('machine' => '6300 #2')
  6.       );
  7.    
  8.    $db2 = array(
  9.       "Mazak 650" => array(array('serial' => 'T7040960'), array('serial' => 'T7040963')),
  10.       "DMG1" => array(array('serial' => 'T7040961')),
  11.       "6300 #2" => array(array('serial' => 'T7040962'))  
  12.       );
  13.      
  14.     $table      = array();
  15.     $table_keys = array();
  16.     $ii=0;
  17.      
  18.  
  19.     foreach($db1 as $mch) {
  20.         $table_keys[] = $mch['machine'];
  21. //var_dump($db2[$mch['machine']]);
  22.         foreach ($db2[$mch['machine']] as $ord) {
  23.              
  24.             $table[$ii][$mch['machine']] = $ord['serial'];
  25.      $ii++;
  26.         }
  27.       $ii=0;
  28.     }
  29.      
  30.    //var_dump($table);
  31.     // Reset counter
  32.     $ii = 0;
  33.      
  34.     // Then build the final output
  35.      
  36.     ?>
  37.     <table border="2" cellspacing="0" cellpadding="0">
  38.       <tr>
  39.         <td><?php echo implode('</td><td>', $table_keys); ?></td>
  40.       </tr>
  41.       <?php foreach($table as $key => $table_row) { ?>
  42.       <tr>
  43.         <?php foreach($table_keys as $value) {
  44.             echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value] : '&nbsp;') .'</td>';
  45.       } ?>
  46.       </tr>
  47.       <?php $ii++; } ?>
  48.  
  49.  


output on this code is
HTML Code: [ Select ]
<table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td>Mazak 650</td><td>DMG1</td><td>6300 #2</td>
      </tr>
            <tr>
        <td>T7040960</td><td>T7040961</td><td>T7040962</td>      </tr>
            <tr>
        <td>T7040963</td><td>&nbsp;</td><td>&nbsp;</td>      </tr>
      </table>
 
  1. <table border="2" cellspacing="0" cellpadding="0">
  2.       <tr>
  3.         <td>Mazak 650</td><td>DMG1</td><td>6300 #2</td>
  4.       </tr>
  5.             <tr>
  6.         <td>T7040960</td><td>T7040961</td><td>T7040962</td>      </tr>
  7.             <tr>
  8.         <td>T7040963</td><td>&nbsp;</td><td>&nbsp;</td>      </tr>
  9.       </table>
  10.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

erm hang on captin.
How can i go about pulling more info from the table as tom.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

serial = 70323432
week = 5
part = x19541
size = 12.5

I dont care about the colors. That part is easy.
demonmaestro wrote:
This is how i want it to look
demonmaestro wrote:
Image
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

use the whole database row instead of $ord['serial'] and on the output declare what you what to output
PHP Code: [ Select ]
        <?
         
        $table      = array();
        $table_keys = array();
        $ii=0;
         
        $m =  "SELECT  * FROM bob";
        $stored_machines = mysql_query($m);
        while ($mch = mysql_fetch_array($stored_machines)) {
            $table_keys[] = $mch['machine']; // Fixed the ;
            $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
            while ($ord = mysql_fetch_array($stored_orders)) {
                 
                $table[$ii][$mch['machine']] = $ord; // Use the whole Database row here
                $ii++; // Added the $ii++
            }
            $ii=0; // Reset the counter
        }
         
// Then build the final output
     
    ?>
    option one
    <table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <?php foreach($table as $key => $table_row) { ?>
      <tr>
        <?php foreach($table_keys as $value) {
            echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'<br />'. $table_row[$value]['part'] .'<br />'. $table_row[$value]['size'] : '&nbsp;') .'</td>';
      } ?>
      </tr>
      <?php } ?>
</table>
    option Two
    <table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <?php foreach($table as $key => $table_row) { ?>
      <tr>
        <?php foreach($table_keys as $value) {
            echo '<td>';
         if(is_array($table_row[$value])) {
            echo '
                  <table border="1" cellspacing="0" cellpadding="0">
                     <tr>
                        <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
                     </tr>
                     <tr>
                        <td>'. $table_row[$value]['part'] .'</td>
                     </tr>
                     <tr>
                        <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
                     </tr>
                  </table>';
         }
         echo '</td>';
      } ?>
      </tr>
      <?php } ?>
</table>
 
  1.         <?
  2.          
  3.         $table      = array();
  4.         $table_keys = array();
  5.         $ii=0;
  6.          
  7.         $m =  "SELECT  * FROM bob";
  8.         $stored_machines = mysql_query($m);
  9.         while ($mch = mysql_fetch_array($stored_machines)) {
  10.             $table_keys[] = $mch['machine']; // Fixed the ;
  11.             $stored_orders = mysql_query("SELECT  * FROM tom WHERE status = ('".$mch['machine']."')");      
  12.             while ($ord = mysql_fetch_array($stored_orders)) {
  13.                  
  14.                 $table[$ii][$mch['machine']] = $ord; // Use the whole Database row here
  15.                 $ii++; // Added the $ii++
  16.             }
  17.             $ii=0; // Reset the counter
  18.         }
  19.          
  20. // Then build the final output
  21.      
  22.     ?>
  23.     option one
  24.     <table border="2" cellspacing="0" cellpadding="0">
  25.       <tr>
  26.         <td><?php echo implode('</td><td>', $table_keys); ?></td>
  27.       </tr>
  28.       <?php foreach($table as $key => $table_row) { ?>
  29.       <tr>
  30.         <?php foreach($table_keys as $value) {
  31.             echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'<br />'. $table_row[$value]['part'] .'<br />'. $table_row[$value]['size'] : '&nbsp;') .'</td>';
  32.       } ?>
  33.       </tr>
  34.       <?php } ?>
  35. </table>
  36.     option Two
  37.     <table border="2" cellspacing="0" cellpadding="0">
  38.       <tr>
  39.         <td><?php echo implode('</td><td>', $table_keys); ?></td>
  40.       </tr>
  41.       <?php foreach($table as $key => $table_row) { ?>
  42.       <tr>
  43.         <?php foreach($table_keys as $value) {
  44.             echo '<td>';
  45.          if(is_array($table_row[$value])) {
  46.             echo '
  47.                   <table border="1" cellspacing="0" cellpadding="0">
  48.                      <tr>
  49.                         <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
  50.                      </tr>
  51.                      <tr>
  52.                         <td>'. $table_row[$value]['part'] .'</td>
  53.                      </tr>
  54.                      <tr>
  55.                         <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
  56.                      </tr>
  57.                   </table>';
  58.          }
  59.          echo '</td>';
  60.       } ?>
  61.       </tr>
  62.       <?php } ?>
  63. </table>
  64.  


my test code
PHP Code: [ Select ]
    <?php
   $db1 = array(
      array('machine' => 'Mazak 650'),
      array('machine' => 'DMG1'),
      array('machine' => '6300 #2')
      );
   
   $db2 = array(
      "Mazak 650" => array(array('serial' => 'T7040960', 'week' => '5', 'part' => 'x19541', 'size' => '12.5'), array('serial' => 'T7040963', 'week' => '6', 'part' => 'x19552', 'size' => '13')),
      "DMG1" => array(array('serial' => 'T7040961', 'week' => '7', 'part' => 'x19563', 'size' => '13.5')),
      "6300 #2" => array(array('serial' => 'T7040962', 'week' => '8', 'part' => 'x19574', 'size' => '14'))   
      );
     
    $table      = array();
    $table_keys = array();
    $ii=0;
     
 
    foreach($db1 as $mch) {
        $table_keys[] = $mch['machine'];
//var_dump($db2[$mch['machine']]);
        foreach ($db2[$mch['machine']] as $ord) {
             
            $table[$ii][$mch['machine']] = $ord;
     $ii++;
        }
      $ii=0;
    }
     
    // Then build the final output
     
    ?>
    option one
    <table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <?php foreach($table as $key => $table_row) { ?>
      <tr>
        <?php foreach($table_keys as $value) {
            echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'<br />'. $table_row[$value]['part'] .'<br />'. $table_row[$value]['size'] : '&nbsp;') .'</td>';
      } ?>
      </tr>
      <?php } ?>
</table>
    option Two
    <table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <?php foreach($table as $key => $table_row) { ?>
      <tr>
        <?php foreach($table_keys as $value) {
            echo '<td>';
         if(is_array($table_row[$value])) {
            echo '
                  <table border="1" cellspacing="0" cellpadding="0">
                     <tr>
                        <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
                     </tr>
                     <tr>
                        <td>'. $table_row[$value]['part'] .'</td>
                     </tr>
                     <tr>
                        <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
                     </tr>
                  </table>';
         }
         echo '</td>';
      } ?>
      </tr>
      <?php } ?>
</table>
 
  1.     <?php
  2.    $db1 = array(
  3.       array('machine' => 'Mazak 650'),
  4.       array('machine' => 'DMG1'),
  5.       array('machine' => '6300 #2')
  6.       );
  7.    
  8.    $db2 = array(
  9.       "Mazak 650" => array(array('serial' => 'T7040960', 'week' => '5', 'part' => 'x19541', 'size' => '12.5'), array('serial' => 'T7040963', 'week' => '6', 'part' => 'x19552', 'size' => '13')),
  10.       "DMG1" => array(array('serial' => 'T7040961', 'week' => '7', 'part' => 'x19563', 'size' => '13.5')),
  11.       "6300 #2" => array(array('serial' => 'T7040962', 'week' => '8', 'part' => 'x19574', 'size' => '14'))   
  12.       );
  13.      
  14.     $table      = array();
  15.     $table_keys = array();
  16.     $ii=0;
  17.      
  18.  
  19.     foreach($db1 as $mch) {
  20.         $table_keys[] = $mch['machine'];
  21. //var_dump($db2[$mch['machine']]);
  22.         foreach ($db2[$mch['machine']] as $ord) {
  23.              
  24.             $table[$ii][$mch['machine']] = $ord;
  25.      $ii++;
  26.         }
  27.       $ii=0;
  28.     }
  29.      
  30.     // Then build the final output
  31.      
  32.     ?>
  33.     option one
  34.     <table border="2" cellspacing="0" cellpadding="0">
  35.       <tr>
  36.         <td><?php echo implode('</td><td>', $table_keys); ?></td>
  37.       </tr>
  38.       <?php foreach($table as $key => $table_row) { ?>
  39.       <tr>
  40.         <?php foreach($table_keys as $value) {
  41.             echo '<td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'<br />'. $table_row[$value]['part'] .'<br />'. $table_row[$value]['size'] : '&nbsp;') .'</td>';
  42.       } ?>
  43.       </tr>
  44.       <?php } ?>
  45. </table>
  46.     option Two
  47.     <table border="2" cellspacing="0" cellpadding="0">
  48.       <tr>
  49.         <td><?php echo implode('</td><td>', $table_keys); ?></td>
  50.       </tr>
  51.       <?php foreach($table as $key => $table_row) { ?>
  52.       <tr>
  53.         <?php foreach($table_keys as $value) {
  54.             echo '<td>';
  55.          if(is_array($table_row[$value])) {
  56.             echo '
  57.                   <table border="1" cellspacing="0" cellpadding="0">
  58.                      <tr>
  59.                         <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
  60.                      </tr>
  61.                      <tr>
  62.                         <td>'. $table_row[$value]['part'] .'</td>
  63.                      </tr>
  64.                      <tr>
  65.                         <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
  66.                      </tr>
  67.                   </table>';
  68.          }
  69.          echo '</td>';
  70.       } ?>
  71.       </tr>
  72.       <?php } ?>
  73. </table>
  74.  


Output
HTML Code: [ Select ]
        option one
    <table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td>Mazak 650</td><td>DMG1</td><td>6300 #2</td>
      </tr>
            <tr>
        <td>T7040960&nbsp;5<br />x19541<br />12.5</td><td>T7040961&nbsp;7<br />x19563<br />13.5</td><td>T7040962&nbsp;8<br />x19574<br />14</td>      </tr>
            <tr>
        <td>T7040963&nbsp;6<br />x19552<br />13</td><td>&nbsp;</td><td>&nbsp;</td>      </tr>
      </table>
    option Two
    <table border="2" cellspacing="0" cellpadding="0">
      <tr>
        <td>Mazak 650</td><td>DMG1</td><td>6300 #2</td>
      </tr>
            <tr>
        <td>
                  <table border="1" cellspacing="0" cellpadding="0">
                     <tr>
                        <td>T7040960&nbsp;5</td>
                     </tr>
                     <tr>
                        <td>x19541</td>
                     </tr>
                     <tr>
                        <td>12.5</td>
                     </tr>
                  </table></td><td>
                  <table border="1" cellspacing="0" cellpadding="0">
                     <tr>
                        <td>T7040961&nbsp;7</td>
                     </tr>
                     <tr>
                        <td>x19563</td>
                     </tr>
                     <tr>
                        <td>13.5</td>
                     </tr>
                  </table></td><td>
                  <table border="1" cellspacing="0" cellpadding="0">
                     <tr>
                        <td>T7040962&nbsp;8</td>
                     </tr>
                     <tr>
                        <td>x19574</td>
                     </tr>
                     <tr>
                        <td>14</td>
                     </tr>
                  </table></td>      </tr>
            <tr>
        <td>
                  <table border="1" cellspacing="0" cellpadding="0">
                     <tr>
                        <td>T7040963&nbsp;6</td>
                     </tr>
                     <tr>
                        <td>x19552</td>
                     </tr>
                     <tr>
                        <td>13</td>
                     </tr>
                  </table></td><td></td><td></td>      </tr>
      </table>
 
  1.         option one
  2.     <table border="2" cellspacing="0" cellpadding="0">
  3.       <tr>
  4.         <td>Mazak 650</td><td>DMG1</td><td>6300 #2</td>
  5.       </tr>
  6.             <tr>
  7.         <td>T7040960&nbsp;5<br />x19541<br />12.5</td><td>T7040961&nbsp;7<br />x19563<br />13.5</td><td>T7040962&nbsp;8<br />x19574<br />14</td>      </tr>
  8.             <tr>
  9.         <td>T7040963&nbsp;6<br />x19552<br />13</td><td>&nbsp;</td><td>&nbsp;</td>      </tr>
  10.       </table>
  11.     option Two
  12.     <table border="2" cellspacing="0" cellpadding="0">
  13.       <tr>
  14.         <td>Mazak 650</td><td>DMG1</td><td>6300 #2</td>
  15.       </tr>
  16.             <tr>
  17.         <td>
  18.                   <table border="1" cellspacing="0" cellpadding="0">
  19.                      <tr>
  20.                         <td>T7040960&nbsp;5</td>
  21.                      </tr>
  22.                      <tr>
  23.                         <td>x19541</td>
  24.                      </tr>
  25.                      <tr>
  26.                         <td>12.5</td>
  27.                      </tr>
  28.                   </table></td><td>
  29.                   <table border="1" cellspacing="0" cellpadding="0">
  30.                      <tr>
  31.                         <td>T7040961&nbsp;7</td>
  32.                      </tr>
  33.                      <tr>
  34.                         <td>x19563</td>
  35.                      </tr>
  36.                      <tr>
  37.                         <td>13.5</td>
  38.                      </tr>
  39.                   </table></td><td>
  40.                   <table border="1" cellspacing="0" cellpadding="0">
  41.                      <tr>
  42.                         <td>T7040962&nbsp;8</td>
  43.                      </tr>
  44.                      <tr>
  45.                         <td>x19574</td>
  46.                      </tr>
  47.                      <tr>
  48.                         <td>14</td>
  49.                      </tr>
  50.                   </table></td>      </tr>
  51.             <tr>
  52.         <td>
  53.                   <table border="1" cellspacing="0" cellpadding="0">
  54.                      <tr>
  55.                         <td>T7040963&nbsp;6</td>
  56.                      </tr>
  57.                      <tr>
  58.                         <td>x19552</td>
  59.                      </tr>
  60.                      <tr>
  61.                         <td>13</td>
  62.                      </tr>
  63.                   </table></td><td></td><td></td>      </tr>
  64.       </table>
  65.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

That was it. You are the man. I also got it currently where the whole thing scrolls but i am unable to figure out how to make each machine need to scroll if too long. I need it both. So if get too many machines to fit on the page only it will scroll side to side but if a particular machine has more orders than the other only that machine will have a scroll for those orders.

PHP Code: [ Select ]
<div style="overflow:auto; height:200px;">
 <table border="0" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php echo implode('</td><td>', $table_keys); ?></td>
      </tr>
      <?php foreach($table as $key => $table_row) { ?>
      <tr>
        <?php foreach($table_keys as $value) {
            echo '<td>';
         if(is_array($table_row[$value])) {
            echo '
                 <table border="1" cellspacing="0" cellpadding="0">
                    <tr>
                       <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
                    </tr>
                    <tr>
                       <td>'. $table_row[$value]['part'] .'</td>
                    </tr>
                    <tr>
                       <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
                    </tr>
                 </table>';
         }
         echo '</td>';
      } ?>
      </tr>
      <?php } ?>
</table>
      </div>
 
  1. <div style="overflow:auto; height:200px;">
  2.  <table border="0" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  3.       <tr>
  4.         <td><?php echo implode('</td><td>', $table_keys); ?></td>
  5.       </tr>
  6.       <?php foreach($table as $key => $table_row) { ?>
  7.       <tr>
  8.         <?php foreach($table_keys as $value) {
  9.             echo '<td>';
  10.          if(is_array($table_row[$value])) {
  11.             echo '
  12.                  <table border="1" cellspacing="0" cellpadding="0">
  13.                     <tr>
  14.                        <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
  15.                     </tr>
  16.                     <tr>
  17.                        <td>'. $table_row[$value]['part'] .'</td>
  18.                     </tr>
  19.                     <tr>
  20.                        <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
  21.                     </tr>
  22.                  </table>';
  23.          }
  24.          echo '</td>';
  25.       } ?>
  26.       </tr>
  27.       <?php } ?>
  28. </table>
  29.       </div>
  30.  
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

How were you thinking on displaying it?

Option 1 on the div tag you could set the width and it should result in something like
Attachments:
dis1.jpg


or

Option 2 would require a different table setup
Attachments:
dis2.jpg
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

option 2 is what i am looking for.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

this might work for you

EDIT:: NOPE lol

RE-EDIT:: This does however
PHP Code: [ Select ]
    <div style="overflow:auto; width:800px;">
     <table border="0" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
          <tr>
            <td><?php echo implode('</td><td>', $table_keys); ?></td>
          </tr>
          <tr>
          <?php foreach($table_keys as $value) {
              echo '<td><div style="overflow:auto; height:200px;">';
              foreach($table as $key => $table_row) {
           
               
             if(is_array($table_row[$value])) {
                echo '
                    <table border="1" cellspacing="0" cellpadding="0">
                       <tr>
                          <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
                       </tr>
                       <tr>
                          <td>'. $table_row[$value]['part'] .'</td>
                       </tr>
                       <tr>
                          <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
                       </tr>
                    </table>';
             }
             
          } echo '</div></td>';?>
         
          <?php } ?>
       </tr>
    </table>
          </div>
 
  1.     <div style="overflow:auto; width:800px;">
  2.      <table border="0" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  3.           <tr>
  4.             <td><?php echo implode('</td><td>', $table_keys); ?></td>
  5.           </tr>
  6.           <tr>
  7.           <?php foreach($table_keys as $value) {
  8.               echo '<td><div style="overflow:auto; height:200px;">';
  9.               foreach($table as $key => $table_row) {
  10.            
  11.                
  12.              if(is_array($table_row[$value])) {
  13.                 echo '
  14.                     <table border="1" cellspacing="0" cellpadding="0">
  15.                        <tr>
  16.                           <td>'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'&nbsp;'. $table_row[$value]['week'] .'</td>
  17.                        </tr>
  18.                        <tr>
  19.                           <td>'. $table_row[$value]['part'] .'</td>
  20.                        </tr>
  21.                        <tr>
  22.                           <td>'. $table_row[$value]['size'] : '&nbsp;') .'</td>
  23.                        </tr>
  24.                     </table>';
  25.              }
  26.              
  27.           } echo '</div></td>';?>
  28.          
  29.           <?php } ?>
  30.        </tr>
  31.     </table>
  32.           </div>
  33.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

That works I am missing something though and cannot figure it out.
I am trying to make it where there is an area below each machine number that will say "In Machine" and will have what ever bit that is in the machine. while having whats lined up for the machines under "Machine Que"

I got the "Machine Que" where i want it but the issue is getting the in machine part to show up correctly.
there is a row under bits that will say yes/no if its in the machine or not.

Also trying to get the bits that are "hot" and Ultra Hot" to go on top of all orders under that machine.
So like its saying ultra hot is above hot. but both need to be on top of the other orders.
Hot and UltraHot has there own row in the table (0/1)

Like this on layout
Image

PHP Code: [ Select ]
       
        $table      = array();
        $table_keys = array();
        $ii=0;
         
        $m =  "SELECT  * FROM BitMachine";
        $stored_machines = mysql_query($m);
        while ($mch = mysql_fetch_array($stored_machines)) {
            $table_keys[] = $mch['machine']; // Fixed the ;
            $stored_orders = mysql_query("SELECT  * FROM bits WHERE status = ('".$mch['machine']."')");      
            while ($ord = mysql_fetch_array($stored_orders)) {
                 
                $table[$ii][$mch['machine']] = $ord; // Use the whole Database row here
                $ii++; // Added the $ii++
            }
            $ii=0; // Reset the counter
        }
         
// Then build the final output
     
    ?>
<style>
a:link {color:#000000; text-decoration:none;}    /* unvisited link */
a:visited {color:#000000; text-decoration:none;} /* visited link */
a:hover {color:#000000; text-decoration:none;}   /* mouse over link */
a:active {color:#000000; text-decoration:none;}  /* selected link */
</style>    
   
    <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">Machine Que<div style="overflow:auto; height:200px; width:110px;">';
              foreach($table as $key => $table_row) {
             if(is_array($table_row[$value])) {
                  if($table_row[$value]['type']=='STEEL'){ echo '<div style="background-color:#FF9999;">';}
          else if($table_row[$value]['type']=='SLIM'){ echo '<div style="background-color:#9999FF;">';}
          else if($table_row[$value]['type']=='KYMERA'){ echo '<div style="background-color:#FF2626;">';}
          else if($table_row[$value]['type']=='HYBRID'){ echo '<div style="background-color:#FF2626;">';}
          else if($table_row[$value]['type']=='EZC'){ echo '<div style="background-color:#FFFF26;">';}
          else if($table_row[$value]['type']=='RWD'){ echo '<div style="background-color:#FF9326;">';}
          else if($table_row[$value]['type']=='EZR'){ echo '<div style="background-color:#FFFF26;">';}
          else if($table_row[$value]['type']=='EZB'){ echo '<div style="background-color:#FFFF26;">';}
            echo '<a href="operator.php?id='.$table_row[$value]['serial'].'"><div style="border:solid; border-color:#000000;">
                   <table border="0" cellspacing="0" cellpadding="0" width="100%">';
                  if($table_row[$value]['ultrahot']=='1'){echo'<tr><td><div style="background-color:#FF0000;">*Ultra Hot*</div></td></tr>';}
                  if($table_row[$value]['hot']=='1'){echo'<tr><td><div style="background-color:#FF0000;">*HOT*</div></td></tr>';}
                  echo '<tr>
                         <td><a href="operator.php?id='.$table_row[$value]['serial'].'">'. (!empty($table_row[$value]) ? $table_row[$value]['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='.$table_row[$value]['serial'].'">'. $table_row[$value]['crown'] .'</a></td>
                      </tr>
                      <tr>
                         <td><a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['size'] : '&nbsp;') .'</a></td>
                      </tr>
                   </table></div></a>';
             }
             
          } echo '</div></td>';?>
         
          <?php } ?>
       </tr>
    </table>
          </div>
 
  1.        
  2.         $table      = array();
  3.         $table_keys = array();
  4.         $ii=0;
  5.          
  6.         $m =  "SELECT  * FROM BitMachine";
  7.         $stored_machines = mysql_query($m);
  8.         while ($mch = mysql_fetch_array($stored_machines)) {
  9.             $table_keys[] = $mch['machine']; // Fixed the ;
  10.             $stored_orders = mysql_query("SELECT  * FROM bits WHERE status = ('".$mch['machine']."')");      
  11.             while ($ord = mysql_fetch_array($stored_orders)) {
  12.                  
  13.                 $table[$ii][$mch['machine']] = $ord; // Use the whole Database row here
  14.                 $ii++; // Added the $ii++
  15.             }
  16.             $ii=0; // Reset the counter
  17.         }
  18.          
  19. // Then build the final output
  20.      
  21.     ?>
  22. <style>
  23. a:link {color:#000000; text-decoration:none;}    /* unvisited link */
  24. a:visited {color:#000000; text-decoration:none;} /* visited link */
  25. a:hover {color:#000000; text-decoration:none;}   /* mouse over link */
  26. a:active {color:#000000; text-decoration:none;}  /* selected link */
  27. </style>    
  28.    
  29.     <div style="overflow:auto; width:100%; height:100%">
  30.      <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  31.           <tr>
  32.             <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  33.           </tr>
  34.           <tr>
  35.           <?php foreach($table_keys as $value) {
  36.               echo '<td align="center">Machine Que<div style="overflow:auto; height:200px; width:110px;">';
  37.               foreach($table as $key => $table_row) {
  38.              if(is_array($table_row[$value])) {
  39.                   if($table_row[$value]['type']=='STEEL'){ echo '<div style="background-color:#FF9999;">';}
  40.           else if($table_row[$value]['type']=='SLIM'){ echo '<div style="background-color:#9999FF;">';}
  41.           else if($table_row[$value]['type']=='KYMERA'){ echo '<div style="background-color:#FF2626;">';}
  42.           else if($table_row[$value]['type']=='HYBRID'){ echo '<div style="background-color:#FF2626;">';}
  43.           else if($table_row[$value]['type']=='EZC'){ echo '<div style="background-color:#FFFF26;">';}
  44.           else if($table_row[$value]['type']=='RWD'){ echo '<div style="background-color:#FF9326;">';}
  45.           else if($table_row[$value]['type']=='EZR'){ echo '<div style="background-color:#FFFF26;">';}
  46.           else if($table_row[$value]['type']=='EZB'){ echo '<div style="background-color:#FFFF26;">';}
  47.             echo '<a href="operator.php?id='.$table_row[$value]['serial'].'"><div style="border:solid; border-color:#000000;">
  48.                    <table border="0" cellspacing="0" cellpadding="0" width="100%">';
  49.                   if($table_row[$value]['ultrahot']=='1'){echo'<tr><td><div style="background-color:#FF0000;">*Ultra Hot*</div></td></tr>';}
  50.                   if($table_row[$value]['hot']=='1'){echo'<tr><td><div style="background-color:#FF0000;">*HOT*</div></td></tr>';}
  51.                   echo '<tr>
  52.                          <td><a href="operator.php?id='.$table_row[$value]['serial'].'">'. (!empty($table_row[$value]) ? $table_row[$value]['serial'] .'</a>&nbsp;<a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['load wk'] .'</a></td>
  53.                       </tr>
  54.                       <tr>
  55.                          <td><a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['crown'] .'</a></td>
  56.                       </tr>
  57.                       <tr>
  58.                          <td><a href="operator.php?id='.$table_row[$value]['serial'].'">'. $table_row[$value]['size'] : '&nbsp;') .'</a></td>
  59.                       </tr>
  60.                    </table></div></a>';
  61.              }
  62.              
  63.           } echo '</div></td>';?>
  64.          
  65.           <?php } ?>
  66.        </tr>
  67.     </table>
  68.           </div>
  69.  



Side note: You are probably like :hmm: "Look at this guy." If you give me your PayPal address or BTC address I will give a "Thank you for the help donation". :mrgreen:
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Hi Josh,

I am looking at the PHP code you just posted, and there is one thing I see that I want to mention before addressing your issue. That is the fact that you are doing a MySQL query in a loop. When I write scripts I always, always avoid ever putting queries into loops as it can add tons of extra queries to the database when probably not needed. A better way to go would be on your initial query to do a join on the bits table where 'status' is equal to 'machine'. That way all you need is that one query, and then when you loop through everything you will still have what you needed, but one MySQL query to do all of this. The way it is right now there could be N number of queries, depending on the number of results in bitmachine. So if you had 1000 things in bitmachine, then you would have 1000 additional MySQL queries. Extremely inefficient, and could slow things down.

So whenever you write a script, if you see a MySQL query inside of a loop, immediately a red flag should go off that things could probably be done differently (probably just with a JOIN).

As far as to your actual question, looks like in your code you don't have any of the "In Machine" stuff yet. What I would do way above where you even start your HTML is to create one array for your Machine Que if the item should fall in there, and then another array for your "In Machine" for if your item should fall in that instead. Then down in your HTML you could just loop through how you are doing it for the Machine Que for the In Machine with the other array in another table row right before it.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

but the info for the machine que and in machine is all in the same table.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

What i am saying is this

Ultra hot orders need to be on the very top of the list
Hot orders need to be at the top of the list
then you got regular orders that will show up in the list in order as they were put in
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9185
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

It is okay if they are in the same table, as long as you can differentiate them in your loop where you build your $table array, you could then add another array to separate them out, and only add to the appropriate array in the loop. Then below in your HTML you can go through each one for your separate areas.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • 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: 483

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: 760
  • 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: 8488
  • 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: 483

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: 760
  • 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: 483

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: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

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

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: 760
  • 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: 483

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: 760
  • 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: 483

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: 760
  • 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: 8488
  • 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: 760
  • 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: 8488
  • 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: 760
  • 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: 760
  • 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: 483

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: 760
  • 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: 8488
  • 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: 760
  • 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: 8488
  • 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: 760
  • 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: 483

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: 483

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: 760
  • 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: 483

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: 760
  • 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
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

OK ... so i think i have an idea of whats going on and how to go about fixing it again i'm not by my computer and these posts are being sent with my phone but i believe the issue lies in the building of the table array the content is being over written the variable $ii i used previously is removed from this code. but what does confusing me is your saying once you add more content to the db it goes back to the side by side? is that correct?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

no.
it just does not show up.
Image
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

Ok that confirms my theory when I get to my computer I'll put the counts in the code
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

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)
{
    // Create 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='.$row['serial'].'">'. $row['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(isset($rows[$value]))
        {
            // Loop through the values that are in the on machine row of the table
            foreach($rows[$value] as $key => $table_row)
            {
                // Check for NULL
                if(isset($table_row[$type]['status']))
                {
                    // Build the ultra hot table
                    if($table_row[$type]['status']['ultrahot'])
                    {
                        $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'ultrahot');
                    }
                   
                    // Build the hot table
                    if($table_row[$type]['status']['hot'])
                    {
                        $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'hot');
                    }
 
                    // Build the normal table
                    if($table_row[$type]['status']['status'])
                    {
                        $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['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_assoc($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;
    }
    elseif($row['hot'])
    {
        $table[$row['machine']][][$on_machine]['hot'] = $row;
    }
    else
    {
        $table[$row['machine']][][$on_machine]['status'] = $row;
    }
   
    $table_keys = array_unique($table_keys);
   
}
 //print_r($table);
?>
 
<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.  
  7. // These are functions to help make the code nicer and easier to read and by all means not required
  8. // This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
  9. function tab($number = 1)
  10. {
  11.     // Call repeat_string and return the tabs
  12.     return repeat_string("\t", $number);
  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. // This function will build a string with a certain number of repeats. Example \r\n\r\n
  23. function repeat_string($type, $number = 1)
  24. {
  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.     // Return the hard space
  37.     return implode('', $return);
  38.    
  39. }
  40.  
  41. // This function is a pretty vardump
  42. function pd($input)
  43. {
  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.     // Create 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.     {
  59.         case 'STEEL':
  60.             $return[] = tab(5) .'<div style="background-color:#FF9999;">';
  61.             break;
  62.         case 'SLIM':
  63.             $return[] = tab(5) .'<div style="background-color:#9999FF;">';
  64.             break;
  65.         case 'KYMERA':
  66.             $return[] = tab(5) .'<div style="background-color:#FF2626;">';
  67.             break;
  68.         case 'HYBRID':
  69.             $return[] = tab(5) .'<div style="background-color:#FF2626;">';
  70.             break;
  71.         case 'EZC':
  72.             $return[] = tab(5) .'<div style="background-color:#FFFF26;">';
  73.             break;
  74.         case 'RWD':
  75.             $return[] = tab(5) .'<div style="background-color:#FF9326;">';
  76.             break;
  77.         case 'EZR':
  78.             $return[] = tab(5) .'<div style="background-color:#FFFF26;">';
  79.             break;
  80.         case 'EZB':
  81.             $return[] = tab(5) .'<div style="background-color:#FFFF26;">';
  82.             break;
  83.         default:
  84.             $return[] = tab(5) .'<div>';
  85.     }
  86.    
  87.     // Start building the output
  88.     $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
  89.     $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
  90.     $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
  91.    
  92.    // Take their temperature and add to the output if their temperature matches
  93.     switch($temp)
  94.     {
  95.         case 'ultrahot':
  96.             $return[] = tab(9) .'<tr>';
  97.             $return[] = tab(10) .'<td>';
  98.             $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
  99.             $return[] = tab(10) .'</td>';
  100.             $return[] = tab(9) .'</tr>';
  101.             break;
  102.  
  103.         case 'hot':
  104.             $return[] = tab(9) .'<tr>';
  105.             $return[] = tab(10) .'<td>';
  106.             $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
  107.             $return[] = tab(10) .'</td>';
  108.             $return[] = tab(9) .'</tr>';
  109.             break;
  110.     }
  111.    
  112.     // Finish building the output
  113.     $return[] = tab(9) .'<tr>';
  114.     $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$row['serial'].'">'. $row['load_wk'] .'</a></td>';
  115.     $return[] = tab(9) .'</tr>';
  116.     $return[] = tab(9) .'<tr>';
  117.     $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
  118.     $return[] = tab(9) .'</tr>';
  119.     $return[] = tab(9) .'<tr>';
  120.     $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
  121.     $return[] = tab(9) .'</tr>';
  122.    
  123.         $return[] = tab(8) .'</table>';
  124.         $return[] = tab(7) .'</div>';
  125.         $return[] = tab(6) .'</a>';
  126.         $return[] = tab(5) .'</div>';
  127.  
  128.     // Join and return the output
  129.     return implode(hs(), $return);
  130. }
  131.  
  132. // This function will build and return the table row
  133. function build_row($keys, $rows, $type)
  134. {
  135.    
  136.     // Add return array we must.
  137.     $return = array();
  138.  
  139.     // What type it is do we know. Hmmmm, yes.
  140.     switch($type)
  141.     {
  142.         case '1':
  143.             $text = 'In Machine';
  144.             break;
  145.         case '0':
  146.             $text = 'Machine Que';
  147.             break;
  148.     }
  149.    
  150.     // Loop through the table keys to build the columns
  151.     foreach($keys as $value)
  152.     {
  153.         // Start the output
  154.         $return[] = tab(3) . '<td align="center">';
  155.         $return[] = tab(4) . $text;
  156.         $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
  157.        
  158.         // Make sure we have an array
  159.         if(isset($rows[$value]))
  160.         {
  161.             // Loop through the values that are in the on machine row of the table
  162.             foreach($rows[$value] as $key => $table_row)
  163.             {
  164.                 // Check for NULL
  165.                 if(isset($table_row[$type]['status']))
  166.                 {
  167.                     // Build the ultra hot table
  168.                     if($table_row[$type]['status']['ultrahot'])
  169.                     {
  170.                         $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'ultrahot');
  171.                     }
  172.                    
  173.                     // Build the hot table
  174.                     if($table_row[$type]['status']['hot'])
  175.                     {
  176.                         $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'hot');
  177.                     }
  178.  
  179.                     // Build the normal table
  180.                     if($table_row[$type]['status']['status'])
  181.                     {
  182.                         $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
  183.                     }
  184.                 }
  185.             }
  186.         }
  187.  
  188.         $return[] = tab(4) . '</div>';
  189.         $return[] = tab(3) . '</td>';
  190.  
  191.     }
  192.    
  193.     // Join and return the output
  194.     return implode(hs(), $return);
  195. }
  196.          
  197. // Set SQL Query
  198. $query = "SELECT BitMachine.machine, bits.* FROM BitMachine LEFT JOIN bits ON BitMachine.machine = bits.status";
  199.  
  200. // Execute
  201. $results_key = mysql_query($query) or die(mysql_error());
  202.  
  203. // Make the arrays to hold the table info
  204. $table      = array();
  205. $table_keys = array();
  206.  
  207. // Loop the results
  208. while($row = mysql_fetch_assoc($results_key))
  209. {
  210.    
  211.     // Set the table header
  212.     $table_keys[] = $row['machine'];
  213.  
  214.     // Check to see if this bit is on the machine.
  215.     $on_machine = ($row['onmachine']) ? '1' : '0';
  216.  
  217.     // Sort by temperature starting with ultrahot
  218.     if($row['ultrahot'])
  219.     {
  220.         $table[$row['machine']][][$on_machine]['ultrahot'] = $row;
  221.     }
  222.     elseif($row['hot'])
  223.     {
  224.         $table[$row['machine']][][$on_machine]['hot'] = $row;
  225.     }
  226.     else
  227.     {
  228.         $table[$row['machine']][][$on_machine]['status'] = $row;
  229.     }
  230.    
  231.     $table_keys = array_unique($table_keys);
  232.    
  233. }
  234.  //print_r($table);
  235. ?>
  236.  
  237. <div style="overflow:auto; width:100%; height:100%">
  238.     <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  239.         <tr>
  240.             <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  241.         </tr>
  242.         <tr>
  243.             <?php echo build_row($table_keys, $table, '1'); ?>
  244.         </tr>
  245.         <tr>
  246.             <?php echo build_row($table_keys, $table, '0'); ?>
  247.         </tr>
  248.     </table>
  249. </div>
  250.  
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

That does save from using a counter which I was leaning for. I'd still move the array_unique out of the while so it only fires once. On a side note you could have made use of my pretty dump function pd($table); instead of print_r($table); :wink:
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

I actually have an error there in the suggested fix (where ultrahot and hot won't work). I fixed it in here.

Thanks ScottG. I originally had it outside of the loop, but after 30+ minutes of editing, re-editing the code, I must have moved it in the loop. I don't like how dumps look. Print_rs just displays the keys and values (I view source to see it neat). Var_dumps also tells me the data-type... makes it a bit ugly and crowded for my liking. I guess I could've modified pd($table) to use print_r() instead of var_dump();

Those are nice set of tidy-ing up functions you got there. I might reuse them myself in my own projects :D (if I may :lol: )

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)
{
    if(empty($row['id']))
    {
        return;
    }
 
    // Create 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='.$row['serial'].'">'. $row['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(isset($rows[$value]))
        {
            // Loop through the values that are in the on machine row of the table
            foreach($rows[$value] as $key => $table_row)
            {
                // Check for NULL
                if(isset($table_row[$type]))
                {
                    // Build the ultra hot table
                    if(isset($table_row[$type]['ultrahot']))
                    {
                        $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
                    }
                   
                    // Build the hot table
                    if(isset($table_row[$type]['hot']))
                    {
                        $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
                    }
 
                    // Build the normal table
                    if(isset($table_row[$type]['status']))
                    {
                        $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['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_assoc($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;
    }
    elseif($row['hot'])
    {
        $table[$row['machine']][][$on_machine]['hot'] = $row;
    }
    else
    {
        $table[$row['machine']][][$on_machine]['status'] = $row;
    }
}
 
$table_keys = array_unique($table_keys);
 
?>
 
<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.  
  7. // These are functions to help make the code nicer and easier to read and by all means not required
  8. // This function is just to make code pretty and returns tabs '\t'. This function relies on the repeat_string function
  9. function tab($number = 1)
  10. {
  11.     // Call repeat_string and return the tabs
  12.     return repeat_string("\t", $number);
  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. // This function will build a string with a certain number of repeats. Example \r\n\r\n
  23. function repeat_string($type, $number = 1)
  24. {
  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.     // Return the hard space
  37.     return implode('', $return);
  38.    
  39. }
  40.  
  41. // This function is a pretty vardump
  42. function pd($input)
  43. {
  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.     if(empty($row['id']))
  54.     {
  55.         return;
  56.     }
  57.  
  58.     // Create an array to hold the table
  59.     $return = array();
  60.    
  61.     // Setup the surrounding div tag to properly color the table
  62.     switch($type)
  63.     {
  64.         case 'STEEL':
  65.             $return[] = tab(5) .'<div style="background-color:#FF9999;">';
  66.             break;
  67.         case 'SLIM':
  68.             $return[] = tab(5) .'<div style="background-color:#9999FF;">';
  69.             break;
  70.         case 'KYMERA':
  71.             $return[] = tab(5) .'<div style="background-color:#FF2626;">';
  72.             break;
  73.         case 'HYBRID':
  74.             $return[] = tab(5) .'<div style="background-color:#FF2626;">';
  75.             break;
  76.         case 'EZC':
  77.             $return[] = tab(5) .'<div style="background-color:#FFFF26;">';
  78.             break;
  79.         case 'RWD':
  80.             $return[] = tab(5) .'<div style="background-color:#FF9326;">';
  81.             break;
  82.         case 'EZR':
  83.             $return[] = tab(5) .'<div style="background-color:#FFFF26;">';
  84.             break;
  85.         case 'EZB':
  86.             $return[] = tab(5) .'<div style="background-color:#FFFF26;">';
  87.             break;
  88.         default:
  89.             $return[] = tab(5) .'<div>';
  90.     }
  91.    
  92.     // Start building the output
  93.     $return[] = tab(6) .'<a href="operator.php?id='. $row['serial'] .'">';
  94.     $return[] = tab(7) .'<div style="border:solid; border-color:#000000;">';
  95.     $return[] = tab(8) .'<table border="0" cellspacing="0" cellpadding="0" width="100%">';
  96.    
  97.    // Take their temperature and add to the output if their temperature matches
  98.     switch($temp)
  99.     {
  100.         case 'ultrahot':
  101.             $return[] = tab(9) .'<tr>';
  102.             $return[] = tab(10) .'<td>';
  103.             $return[] = tab(11) .'<div style="background-color:#FF0000;">*Ultra Hot*</div>';
  104.             $return[] = tab(10) .'</td>';
  105.             $return[] = tab(9) .'</tr>';
  106.             break;
  107.  
  108.         case 'hot':
  109.             $return[] = tab(9) .'<tr>';
  110.             $return[] = tab(10) .'<td>';
  111.             $return[] = tab(11) .'<div style="background-color:#FF0000;">*HOT*</div>';
  112.             $return[] = tab(10) .'</td>';
  113.             $return[] = tab(9) .'</tr>';
  114.             break;
  115.     }
  116.    
  117.     // Finish building the output
  118.     $return[] = tab(9) .'<tr>';
  119.     $return[] = tab(10) .'<td><a href="operator.php?id='. $row['serial'].'">'. $row['serial'] .'</a>&nbsp;<a href="operator.php?id='.$row['serial'].'">'. $row['load_wk'] .'</a></td>';
  120.     $return[] = tab(9) .'</tr>';
  121.     $return[] = tab(9) .'<tr>';
  122.     $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['crown'] .'</a></td>';
  123.     $return[] = tab(9) .'</tr>';
  124.     $return[] = tab(9) .'<tr>';
  125.     $return[] = tab(10) .'<td><a href="operator.php?id='.$row['serial'].'">'. $row['size'] .'</a></td>';
  126.     $return[] = tab(9) .'</tr>';
  127.     $return[] = tab(8) .'</table>';
  128.     $return[] = tab(7) .'</div>';
  129.     $return[] = tab(6) .'</a>';
  130.     $return[] = tab(5) .'</div>';
  131.  
  132.     // Join and return the output
  133.     return implode(hs(), $return);
  134. }
  135.  
  136. // This function will build and return the table row
  137. function build_row($keys, $rows, $type)
  138. {
  139.    
  140.     // Add return array we must.
  141.     $return = array();
  142.  
  143.     // What type it is do we know. Hmmmm, yes.
  144.     switch($type)
  145.     {
  146.         case '1':
  147.             $text = 'In Machine';
  148.             break;
  149.         case '0':
  150.             $text = 'Machine Que';
  151.             break;
  152.     }
  153.    
  154.     // Loop through the table keys to build the columns
  155.     foreach($keys as $value)
  156.     {
  157.         // Start the output
  158.         $return[] = tab(3) . '<td align="center">';
  159.         $return[] = tab(4) . $text;
  160.         $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">';
  161.        
  162.         // Make sure we have an array
  163.         if(isset($rows[$value]))
  164.         {
  165.             // Loop through the values that are in the on machine row of the table
  166.             foreach($rows[$value] as $key => $table_row)
  167.             {
  168.                 // Check for NULL
  169.                 if(isset($table_row[$type]))
  170.                 {
  171.                     // Build the ultra hot table
  172.                     if(isset($table_row[$type]['ultrahot']))
  173.                     {
  174.                         $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
  175.                     }
  176.                    
  177.                     // Build the hot table
  178.                     if(isset($table_row[$type]['hot']))
  179.                     {
  180.                         $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
  181.                     }
  182.  
  183.                     // Build the normal table
  184.                     if(isset($table_row[$type]['status']))
  185.                     {
  186.                         $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
  187.                     }
  188.                 }
  189.             }
  190.         }
  191.  
  192.         $return[] = tab(4) . '</div>';
  193.         $return[] = tab(3) . '</td>';
  194.  
  195.     }
  196.    
  197.     // Join and return the output
  198.     return implode(hs(), $return);
  199. }
  200.          
  201. // Set SQL Query
  202. $query = "SELECT BitMachine.machine, bits.* FROM BitMachine LEFT JOIN bits ON BitMachine.machine = bits.status";
  203.  
  204. // Execute
  205. $results_key = mysql_query($query) or die(mysql_error());
  206.  
  207. // Make the arrays to hold the table info
  208. $table      = array();
  209. $table_keys = array();
  210.  
  211. // Loop the results
  212. while($row = mysql_fetch_assoc($results_key))
  213. {
  214.    
  215.     // Set the table header
  216.     $table_keys[] = $row['machine'];
  217.  
  218.     // Check to see if this bit is on the machine.
  219.     $on_machine = ($row['onmachine']) ? '1' : '0';
  220.  
  221.     // Sort by temperature starting with ultrahot
  222.     if($row['ultrahot'])
  223.     {
  224.         $table[$row['machine']][][$on_machine]['ultrahot'] = $row;
  225.     }
  226.     elseif($row['hot'])
  227.     {
  228.         $table[$row['machine']][][$on_machine]['hot'] = $row;
  229.     }
  230.     else
  231.     {
  232.         $table[$row['machine']][][$on_machine]['status'] = $row;
  233.     }
  234. }
  235.  
  236. $table_keys = array_unique($table_keys);
  237.  
  238. ?>
  239.  
  240. <div style="overflow:auto; width:100%; height:100%">
  241.     <table border="1" bordercolor="#F1090D" cellspacing="0" cellpadding="0">
  242.         <tr>
  243.             <td align="center"><?php echo implode('</td><td>', $table_keys); ?></td>
  244.         </tr>
  245.         <tr>
  246.             <?php echo build_row($table_keys, $table, '1'); ?>
  247.         </tr>
  248.         <tr>
  249.             <?php echo build_row($table_keys, $table, '0'); ?>
  250.         </tr>
  251.     </table>
  252. </div>
  253.  


Here though, for some reason there are empty click-able squares in the Machine Que if there is nothing in the InMachine or the Machine Que.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

I also want to bring your attention to a problem. There is no way to order ultrahot, then hot and then regular since it's coming out of the database in no particular order. You could add 'ORDER BY bits.ultrahot DESC' to the query and then it's guaranteed that at least ultrahot would display first. But this way, you just can't order them like you want without drastically changing the current code as it is (I think).

Also, if you change the SQL from LEFT JOIN to JOIN, you would hide all the empty machines. The machines would appear once there's something to display there. Just makes the entire thing look better in my opinion.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

I use to use print_r() all the time but when the array becomes a string by accident or design i hated seeing the error I too dont like all of the info in th var dump but it runs everything I do however have a similar function called pr() which does just what your modification suggests but i like to say pd lol feel free to use them I've posted variations of those functions on here before.

As for the empty clickable boxes in the function build table at the top add a check to see if there is any info in the $row

something like
PHP Code: [ Select ]
if(empty($row)){
 return;
}
 
  1. if(empty($row)){
  2.  return;
  3. }
  4.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

I need all the machines to show as it is part of a future expansion of the project.

now the ultra hot/hot/regular it needs to be like that because ultrahot bits need to go on first and what ever is up top will go on next to the machine.

so ultrahot bits are hotter than hot bits
hot bits are hotter than regular bits

all need to be ordered by there bitdate unless ultrahot/hot status
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

PHP Code: [ Select ]
if(empty($row['id']))
{
    return;
}
  1. if(empty($row['id']))
  2. {
  3.     return;
  4. }
Did the trick.

I knew I needed that, but I didn't think that that was what was causing it :lol: (A bit of a tounge-twister)

// Edited my previous post to reflect the change
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

demonmaestro wrote:
I need all the machines to show as it is part of a future expansion of the project.

now the ultra hot/hot/regular it needs to be like that because ultrahot bits need to go on first and what ever is up top will go on next to the machine.

so ultrahot bits are hotter than hot bits
hot bits are hotter than regular bits

all need to be ordered by there bitdate unless ultrahot/hot status

That's why I suggest to change the database structure the way I suggested previously. Instead of having 'ultrahot' and 'hot' columns, you'll have only one column 'temperature' with 1 for ultrahot, 2 for hot and 3 for regular. Then you'll 'ORDER BY bits.temperature AND bits.bitdate ASC' (pretty sure you could order 2 fields) and you have what you want. Current way you have is inefficient.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Okay. Well I will make the change in the DB now.
Thats going to throw this out of wack i am sure.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

demonmaestro wrote:
Okay. Well I will make the change in the DB now.
Thats going to throw this out of wack i am sure.

:lol: Yes, we'll have to come up with different code to read the database. If you want you can wait for ScottG, maybe he'll come up with a solution for the way you have it at the moment... just that it's above me right now, and too tired to brainstorm a solution.

Only way I can think of doing it this way right now is by making 3 separate calls to the database.
Code: [ Select ]
SELECT ... FROM ... WHERE ultrahot = 1 ORDER BY ...

while(...)
{

}

SELECT ... FROM ... WHERE hot = 1 ORDER BY ...

while(...)
{

}

SELECT ... FROM ... WHERE ultrahot = 0 AND hot = 0 ORDER BY ...

while(...)
{

}
  1. SELECT ... FROM ... WHERE ultrahot = 1 ORDER BY ...
  2. while(...)
  3. {
  4. }
  5. SELECT ... FROM ... WHERE hot = 1 ORDER BY ...
  6. while(...)
  7. {
  8. }
  9. SELECT ... FROM ... WHERE ultrahot = 0 AND hot = 0 ORDER BY ...
  10. while(...)
  11. {
  12. }
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

The order should be built in with

PHP Code: [ Select ]
// Build the ultra hot table
                    if(isset($table_row[$type]['ultrahot']))
                    {
                        $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
                    }
                   
                    // Build the hot table
                    if(isset($table_row[$type]['hot']))
                    {
                        $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
                    }
 
                    // Build the normal table
                    if(isset($table_row[$type]['status']))
                    {
                        $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
                    }
 
  1. // Build the ultra hot table
  2.                     if(isset($table_row[$type]['ultrahot']))
  3.                     {
  4.                         $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
  5.                     }
  6.                    
  7.                     // Build the hot table
  8.                     if(isset($table_row[$type]['hot']))
  9.                     {
  10.                         $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
  11.                     }
  12.  
  13.                     // Build the normal table
  14.                     if(isset($table_row[$type]['status']))
  15.                     {
  16.                         $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
  17.                     }
  18.  


Since your looping by row then build each column, in each column is a table per bit that's also why i didn't use numbers when setting temps so there is an entry on normal

this also help to sort it
PHP Code: [ Select ]
 // 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;
   }
  1.  // Sort by temperature starting with ultrahot
  2.    if($row['ultrahot']) {
  3.       $table[$row['name']][$on_machine]['ultrahot'] = $row;
  4.    } else if($row['hot']) {
  5.       $table[$row['name']][$on_machine]['hot'] = $row;
  6.    } else {
  7.       $table[$row['name']][$on_machine]['normal'] = $row;
  8.    }
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

ScottG wrote:
The order should be built in with

PHP Code: [ Select ]
// Build the ultra hot table
                    if(isset($table_row[$type]['ultrahot']))
                    {
                        $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
                    }
                   
                    // Build the hot table
                    if(isset($table_row[$type]['hot']))
                    {
                        $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
                    }
 
                    // Build the normal table
                    if(isset($table_row[$type]['status']))
                    {
                        $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
                    }
 
  1. // Build the ultra hot table
  2.                     if(isset($table_row[$type]['ultrahot']))
  3.                     {
  4.                         $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
  5.                     }
  6.                    
  7.                     // Build the hot table
  8.                     if(isset($table_row[$type]['hot']))
  9.                     {
  10.                         $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
  11.                     }
  12.  
  13.                     // Build the normal table
  14.                     if(isset($table_row[$type]['status']))
  15.                     {
  16.                         $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
  17.                     }
  18.  


Since your looping by row then build each column, in each column is a table per bit that's also why i didn't use numbers when setting temps so there is an entry on normal

this also help to sort it
PHP Code: [ Select ]
 // 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;
   }
  1.  // Sort by temperature starting with ultrahot
  2.    if($row['ultrahot']) {
  3.       $table[$row['name']][$on_machine]['ultrahot'] = $row;
  4.    } else if($row['hot']) {
  5.       $table[$row['name']][$on_machine]['hot'] = $row;
  6.    } else {
  7.       $table[$row['name']][$on_machine]['normal'] = $row;
  8.    }

That wouldn't (and doesn't) create the order. I tested it... it just creates it from what it gets in the array. Consider the following array.
Code: [ Select ]
Array
(
  [DMG 2] => Array
    (
      [0] => Array
        (
          [1] => Array
            (
              [status] => Array
                (
                  [machine] => DMG 2
                  [id] => 21
                  [serial] => T7040968
                  [crown] => T588X19681
                  [type] => SLIM
                  [size] => 8.75
                  [status] => DMG 2
                  [load_wk] => 13
                  [hot] => 0
                  [ultrahot] => 0
                  [bitdate] => 16-Apr
                  [onmachine] => 1
                )

            )

        )

      [1] => Array
        (
          [0] => Array
            (
              [status] => Array
                (
                  [machine] => DMG 2
                  [id] => 44
                  [serial] => T7040983
                  [crown] => T588X20618
                  [type] => STEEL
                  [size] => 12.25
                  [status] => DMG 2
                  [load_wk] => 13
                  [hot] => 1
                  [ultrahot] => 0
                  [bitdate] => 3-May
                  [onmachine] => 1
                )

            )

        )

      [2] => Array
        (
          [0] => Array
            (
              [status] => Array
                (
                  [machine] => DMG 2
                  [id] => 56
                  [serial] => T7040986
                  [crown] => T588S11111
                  [type] => STEEL
                  [size] => 12.25
                  [status] => DMG 2
                  [load_wk] => 13
                  [hot] => 0
                  [ultrahot] => 0
                  [bitdate] => 3-May
                  [onmachine] => 1
                )

            )

        )

      [3] => Array
        (
          [1] => Array
            (
              [ultrahot] => Array
                (
                  [machine] => DMG 2
                  [id] => 102
                  [serial] => T7040916
                  [crown] => T588X18821
                  [type] => SLIM
                  [size] => 8.5
                  [status] => DMG 2
                  [load_wk] => 12
                  [hot] => 0
                  [ultrahot] => 1
                  [bitdate] => 12-Apr
                  [onmachine] => 1
                )

            )

        )

    )
)
  1. Array
  2. (
  3.   [DMG 2] => Array
  4.     (
  5.       [0] => Array
  6.         (
  7.           [1] => Array
  8.             (
  9.               [status] => Array
  10.                 (
  11.                   [machine] => DMG 2
  12.                   [id] => 21
  13.                   [serial] => T7040968
  14.                   [crown] => T588X19681
  15.                   [type] => SLIM
  16.                   [size] => 8.75
  17.                   [status] => DMG 2
  18.                   [load_wk] => 13
  19.                   [hot] => 0
  20.                   [ultrahot] => 0
  21.                   [bitdate] => 16-Apr
  22.                   [onmachine] => 1
  23.                 )
  24.             )
  25.         )
  26.       [1] => Array
  27.         (
  28.           [0] => Array
  29.             (
  30.               [status] => Array
  31.                 (
  32.                   [machine] => DMG 2
  33.                   [id] => 44
  34.                   [serial] => T7040983
  35.                   [crown] => T588X20618
  36.                   [type] => STEEL
  37.                   [size] => 12.25
  38.                   [status] => DMG 2
  39.                   [load_wk] => 13
  40.                   [hot] => 1
  41.                   [ultrahot] => 0
  42.                   [bitdate] => 3-May
  43.                   [onmachine] => 1
  44.                 )
  45.             )
  46.         )
  47.       [2] => Array
  48.         (
  49.           [0] => Array
  50.             (
  51.               [status] => Array
  52.                 (
  53.                   [machine] => DMG 2
  54.                   [id] => 56
  55.                   [serial] => T7040986
  56.                   [crown] => T588S11111
  57.                   [type] => STEEL
  58.                   [size] => 12.25
  59.                   [status] => DMG 2
  60.                   [load_wk] => 13
  61.                   [hot] => 0
  62.                   [ultrahot] => 0
  63.                   [bitdate] => 3-May
  64.                   [onmachine] => 1
  65.                 )
  66.             )
  67.         )
  68.       [3] => Array
  69.         (
  70.           [1] => Array
  71.             (
  72.               [ultrahot] => Array
  73.                 (
  74.                   [machine] => DMG 2
  75.                   [id] => 102
  76.                   [serial] => T7040916
  77.                   [crown] => T588X18821
  78.                   [type] => SLIM
  79.                   [size] => 8.5
  80.                   [status] => DMG 2
  81.                   [load_wk] => 12
  82.                   [hot] => 0
  83.                   [ultrahot] => 1
  84.                   [bitdate] => 12-Apr
  85.                   [onmachine] => 1
  86.                 )
  87.             )
  88.         )
  89.     )
  90. )

The last one is ultrahot, 3rd is normal, 2nd is hot and 1st is normal. That loop is going to create them in the order that it receives them... and display as such.

With that array, you are going to have a normal on top, then hot, then normal again and then ultrahot. Array was derived from the database with that script (it's the outcome I got from that script).
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

im not going to touch the DB till something get figured out :lol:
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

ok what about adding to the query

ORDER BY ultrahot DESC, last_hot DESC;

my mind is frying out and i'm still using my phone
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ScottG wrote:
ok what about adding to the query

ORDER BY ultrahot DESC, last_hot DESC;

my mind is frying out and i'm still using my phone



I can tell you even got 404 posts.. :lol:
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

ScottG wrote:
ok what about adding to the query

ORDER BY ultrahot DESC, last_hot DESC;

my mind is frying out and i'm still using my phone

Oh, didn't know that's how you combine ORDER by fields. That did fix it.

I've tried
SQL Code: [ Select ]
SELECT BitMachine.machine, bits.* FROM BitMachine LEFT JOIN bits ON BitMachine.machine = bits.STATUS ORDER BY bits.ultrahot, bits.hot DESC

And that failed... guess I didn't know the proper syntax to do it.

The proper SQL to use is.
SQL Code: [ Select ]
[sql]SELECT BitMachine.machine, bits.* FROM BitMachine LEFT JOIN bits ON BitMachine.machine = bits.STATUS ORDER BY bits.ultrahot DESC, bits.hot DESC, bits.bitdate ASC
(I also included the bitdate ASC order).
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

it appears to be it but it took the machines out of order now...

ha...

//edit added BitMachine.id ASC to the beginning of the ORDER BY
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

SQL Code: [ Select ]
SELECT BitMachine.machine, bits.* FROM BitMachine LEFT JOIN bits ON BitMachine.machine = bits.STATUS ORDER BY BitMachine.machine ASC,  bits.ultrahot DESC, bits.hot DESC, bits.bitdate ASC


// edit... didn't see your edit :lol:
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

so far that appears to be great.

Although i had notice that while it can show more than one bit in the machine. Truly only one but can be ran at a time per machine. So there is no need to have the scroll box on the In Machine row
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

line 160
PHP Code: [ Select ]
if($type) { $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">'; }


line 192

PHP Code: [ Select ]
if($type) { $return[] = tab(4) . '</div>'; }


all together now
PHP Code: [ Select ]
// 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;
        if($type) { $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">'; }
       
        // Make sure we have an array
        if(isset($rows[$value]))
        {
            // Loop through the values that are in the on machine row of the table
            foreach($rows[$value] as $key => $table_row)
            {
                // Check for NULL
                if(isset($table_row[$type]))
                {
                    // Build the ultra hot table
                    if(isset($table_row[$type]['ultrahot']))
                    {
                        $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
                    }
                   
                    // Build the hot table
                    if(isset($table_row[$type]['hot']))
                    {
                        $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
                    }
 
                    // Build the normal table
                    if(isset($table_row[$type]['status']))
                    {
                        $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
                    }
                }
            }
        }
 
        if($type) { $return[] = tab(4) . '</div>'; }
        $return[] = tab(3) . '</td>';
 
    }
   
    // Join and return the output
    return implode(hs(), $return);
}
 
  1. // This function will build and return the table row
  2. function build_row($keys, $rows, $type)
  3. {
  4.    
  5.     // Add return array we must.
  6.     $return = array();
  7.  
  8.     // What type it is do we know. Hmmmm, yes.
  9.     switch($type)
  10.     {
  11.         case '1':
  12.             $text = 'In Machine';
  13.             break;
  14.         case '0':
  15.             $text = 'Machine Que';
  16.             break;
  17.     }
  18.    
  19.     // Loop through the table keys to build the columns
  20.     foreach($keys as $value)
  21.     {
  22.         // Start the output
  23.         $return[] = tab(3) . '<td align="center">';
  24.         $return[] = tab(4) . $text;
  25.         if($type) { $return[] = tab(4) . '<div style="overflow:auto; height:200px; width:110px;">'; }
  26.        
  27.         // Make sure we have an array
  28.         if(isset($rows[$value]))
  29.         {
  30.             // Loop through the values that are in the on machine row of the table
  31.             foreach($rows[$value] as $key => $table_row)
  32.             {
  33.                 // Check for NULL
  34.                 if(isset($table_row[$type]))
  35.                 {
  36.                     // Build the ultra hot table
  37.                     if(isset($table_row[$type]['ultrahot']))
  38.                     {
  39.                         $return[] = build_table($table_row[$type]['ultrahot'], $table_row[$type]['ultrahot']['type'], 'ultrahot');
  40.                     }
  41.                    
  42.                     // Build the hot table
  43.                     if(isset($table_row[$type]['hot']))
  44.                     {
  45.                         $return[] = build_table($table_row[$type]['hot'], $table_row[$type]['hot']['type'], 'hot');
  46.                     }
  47.  
  48.                     // Build the normal table
  49.                     if(isset($table_row[$type]['status']))
  50.                     {
  51.                         $return[] = build_table($table_row[$type]['status'], $table_row[$type]['status']['type'], 'status');
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.  
  57.         if($type) { $return[] = tab(4) . '</div>'; }
  58.         $return[] = tab(3) . '</td>';
  59.  
  60.     }
  61.    
  62.     // Join and return the output
  63.     return implode(hs(), $return);
  64. }
  65.  


EDIT missed a }
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

thats not working captin
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8488
  • Loc: USA

Post 3+ Months Ago

Well, if you're ever going to have only one there, then you won't see the scroll bar even if it's coded in there anyway. I wouldn't worry about it.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

its not that i am worring about it as the height. but i maybe can do that from the table specs and not the div height
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

The div height controls the scroll you could set a class variable in the switch that test the in and que of the machine that would set the height and overflow on the div
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

well couldn't I just do it from the <td> ?
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

I can't think in css right now lol. what was not working about that last part?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

changing the div. it made all the info disapear.

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)
{
    if(empty($row['id']))
    {
        return;
    }
 
    // Create an array to hold the ta