Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ser = "localhost";
- $user = "root";
- $pass = "";
- $db = "machineschedule";
- $con = mysqli_connect($ser, $user, $pass, $db) or die( "connection failed" );
- $sql = "SELECT `status`, `startingtime` , `endingtime` FROM `machine2` ORDER BY `startingtime`";
- $result = mysqli_query( $con, $sql );
- if(mysqli_num_rows($result) == 0)
- {
- echo "<script> location.href='http://localhost/machineschedule/nodata.php'; </script>";
- }
- mysqli_close($con);
- // echo date( 'Y-m-d H:i:s' );
- function printDiv($time , $status='' , $laststatus='',$tsClass='')
- {
- ?>
- <div class='timestamp <?=$tsClass; ?>'>
- <span class='time'>
- <?= date( 'H:i:s' , strtotime($time));?>
- </span>
- <?php
- if( simpleStatus($status) != simpleStatus($laststatus) )
- {
- ?>
- <span class='vertical-line'></span>
- <?php
- }
- ?>
- <div class='line <?= $status; ?>'></div>
- </div>
- <?php
- }
- function newContainer($time)
- {
- //closing last container div
- ?>
- </div>
- <div class="date-title"><?= date('d-m-Y', strtotime($time)); ?></div>
- <div class="container">
- <?php
- }
- function continueNewContainer($time,$status)
- {
- //closing last container div
- ?>
- </div>
- <div class="date-title"><?= date('d-m-Y', strtotime($time)); ?></div>
- <div class="container">
- <div class='timestamp start-arrow'>
- <div class='line <?= $status; ?>'></div>
- </div>
- <?php
- }
- function simpleStatus($status)
- {
- if($status == "working")
- {
- return "working";
- }
- return "off";
- }
- ?>
- <link rel="stylesheet" href="./css/main.css" />
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <?php
- $row = mysqli_fetch_array( $result );
- newContainer($row['startingtime']);
- printDiv( $row['startingtime'], simpleStatus($row['status']) );
- $endtimetemp = $row['endingtime'];
- $laststatus = $row['status'];
- while( $row = mysqli_fetch_array( $result ) )
- {
- if( strtotime($row['startingtime']) != strtotime( $endtimetemp ) )
- {
- printDiv( $endtimetemp , 'no-data' ,$laststatus);
- if( date('d-m-Y', strtotime($endtimetemp)) != date('d-m-Y', strtotime($row['startingtime'])) )
- {
- newContainer($row['startingtime']);
- }
- }
- if( date('d-m-Y', strtotime($row['startingtime'])) != date('d-m-Y', strtotime($row['endingtime'])) )
- {
- printDiv( $row['startingtime'], $row['status'] , $laststatus,'force-line' );
- continueNewContainer( $row['endingtime'], $row['status'] );
- }
- else
- {
- printDiv( $row['startingtime'], $row['status'], $laststatus );
- }
- $endstatustemp = $row['status'];
- $endtimetemp = $row['endingtime'];
- }
- printDiv( $endtimetemp );
- $con = mysqli_connect($ser, $user, $pass, $db) or die( "connection failed" );
- $sql1 = "SELECT `status`, `startingtime` , `endingtime` FROM `machine2` ORDER BY `startingtime`";
- $result = mysqli_query( $con, $sql1 );
- if(mysqli_num_rows($result) == 0)
- {
- echo "<script> location.href='http://localhost/machineschedule/nodata.php'; </script>";
- }
- mysqli_close($con);
- ?>
- </div>
- <table class="data-table">
- <thead>
- <tr>
- <th>Status</th>
- <th>Starting Time</th>
- <th>Ending Time</th>
- </tr>
- </thead>
- <tbody>
- <?php while($row = mysqli_fetch_array($result)){?>
- <tr <?php echo "class=".$row['status']." "; ?>>
- <td><?php echo $row["status"]; ?></td>
- <td><?php echo $row["startingtime"]; ?></td>
- <td><?php echo $row["endingtime"]; ?></td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
Add Comment
Please, Sign In to add comment