Coding PHP | membaca Simpel Tabel

kali ini Abiabang akan share coding php untuk membaca simpel Tabel.

diperlukan 2 buah file (koneksi.php dan index.php)

Untuk isi dari file koneksi.php
<?php
    $server = "192.168.6.xxx:3306";
    $user = "root";
    $pass = "xxxxxxxx.";
    $dbname = "tabel_xxxxx";
   
    mysql_connect($server,$user,$pass);
        mysql_select_db($dbname);
       
   
?>

untuk isi dari file index.php

<head> <meta http-equiv="refresh" content="300"> </head>

<?php

include "koneksi.php";
   
$now = date('Y-m-d');
//$now = '2016-02-06';    
$query = "SELECT SUM(tcsi_qty) as JML
FROM ht_counters_sales_items
WHERE tcsi_mi_id IN (
'4726','4789','4790','4791','4792',
'4793','18080','18081','18082',
'18083','18084','18085','18086',
'18090','18101','18102','18104',
'18108','18110','25868','25877',
'26714','26716','26758','26759',
'26760','26761','26763','26765',
'26788','26825','26891','26897',
'26903','26915','27131','27134',
'27194','27200','27203','27206',
'27224','27455','27599','27602',
'27605','27608','27773','27968',
'28046','28090','28267','28281',
'28284','28287','28521','28527',
'28530','28533','28536','28539',
'28551','28566','28581','28584',
'28596','30199','30203','30207',
'30211','30219','30195','30331',
'30335','30323','30327','30487','30491','30507','30511','30515','30519','30523','30527','29385','4789','29346','30307','29349','30643','29331','29361','31057','31276','31279','31282','31285','31288','31294','31434','31446','31437','30523','28788','31503') AND DATE(tcs_date) = DATE(NOW());";
$query_liburan = "SELECT SUM(tcsi_qty) as JML
FROM ht_counters_sales_items
WHERE tcsi_mi_name IN ('Harga Tiket Masuk', 'HTM Diskon 5%', 'HTM Diskon 10%', 'HTM Diskon 15%', 'HTM Diskon 25%','Tiket Mekarsari A', 'Tiket Mekarsari B','Tiket Mekarsari C', 'Tiket Mekarsari D','Tiket Mekarsari E','Tiket Mekarsari F','Tiket Mekarsari G','Tiket Mekarsari H','Tiket Mekarsari I','NT TRAVELOKA A','Paket Mekarsari A') AND DATE(tcs_date) = DATE(NOW());";
$e = mysql_query($query);
while($row=mysql_fetch_array($e)){
        $visitor = $row['JML'];
        echo '<body style="background-color:#333; color:white;" ><center><h2 style="font-size:50px;">'.substr($visitor,0,-3)    .'</h2    ></body>';
        }
       
$warning = "SELECT COUNT(tcsi_id) as JML_REC FROM ht_counters_sales_items WHERE DATE(tcs_date) = DATE(NOW());";
$rec2 = mysql_query($warning);
while($row2=mysql_fetch_array($rec2)){
        $jml_rec2 = $row2['JML_REC'];
        echo 'JML REC HT_counters_sales_items : '.$jml_rec2. ' records';
        }
?>
 coding ke2

<?php
$now = date('d-m-Y');
$db_host = '192.168.6.6'; // Nama Server
$db_user = 'root'; // User Server
$db_pass = 'badmin123.'; // Password Server
$db_name = 'tbm_productions'; // Nama Database

$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
    die ('Gagal terhubung MySQL: ' . mysqli_connect_error());   
}


//echo "Hari ini Tanggal "---"<br>";
$sql = "SELECT tcsi_mi_code, tcsi_mi_name, sum(ROUND(tcsi_qty,0)) as tcsi_qty FROM ht_counters_sales_items
where tcsi_mi_id
IN ('4726','4789','4790','4791','4792',
'4793','18080','18081','18082',
'18083','18084','18085','18086',
'18090','18101','18102','18104',
'18108','18110','25868','25877',
'26714','26716','26758','26759',
'26760','26761','26763','26765',
'26788','26825','26891','26897',
'26903','26915','27131','27134',
'27194','27200','27203','27206',
'27224','27455','27599','27602',
'27605','27608','27773','27968',
'28046','28090','28267','28281',
'28284','28287','28521','28527',
'28530','28533','28536','28539',
'28551','28566','28581','28584',
'28596','30199','30203','30207',
'30211','30219','30195','30331',
'30335','30323','30327','30487','30491','30507','30511','30515','30519','30523','30527','29385','4789','29346','30307','29349','30643','29331','29361','31057','31276','31279','31282','31285','31288','31294','31434','31446','31437','30523','28788','31503') AND DATE(tcs_date) = DATE(NOW()) group by tcsi_mi_id";




$query = mysqli_query($conn, $sql);




echo "TOTAL PENGUNJUNG : $now<br>";
//echo "$sql1<br>";
//echo $query1;




if (!$query) {
    die ('SQL Error: ' . mysqli_error($conn));
}
   
echo '<html>
        <head>
            <title>Menampilkan Data Tabel MySQL Dengan mysqli_fetch_array</title>
            <style>
                body {font-family:tahoma, arial}
                table {border-collapse: collapse}
                th, td {font-size: 13px; border: 1px solid #DEDEDE; padding: 3px 5px; color: #303030}
                th {background: #CCCCCC; font-size: 12px; border-color:#B0B0B0}
                .subtotal td {background: #F8F8F8}
                .right{text-align: right}
            </style>
        </head>
        <body>
        <table>
        <thead>
            <tr>
                <th>KODE ITEM</th>
                <th>NAMA ITEM</th>
                <th>QTY</th>

            </tr>
        </thead>
        <tbody>';
//echo 'JML REC HT_counters_sales_items : '.$query1. ' records';
       
while ($row = mysqli_fetch_array($query))
{
    echo '<tr>
            <td>'.$row['tcsi_mi_code'].'</td>
            <td>'.$row['tcsi_mi_name'].'</td>
            <td>'.$row['tcsi_qty'].'</td>
        </tr>';

}


$sql1 = "SELECT tcsi_mi_code, tcsi_mi_name, sum(ROUND(tcsi_qty,0)) as tcsi_qty FROM ht_counters_sales_items
where tcsi_mi_id
IN ('4726','4789','4790','4791','4792',
'4793','18080','18081','18082',
'18083','18084','18085','18086',
'18090','18101','18102','18104',
'18108','18110','25868','25877',
'26714','26716','26758','26759',
'26760','26761','26763','26765',
'26788','26825','26891','26897',
'26903','26915','27131','27134',
'27194','27200','27203','27206',
'27224','27455','27599','27602',
'27605','27608','27773','27968',
'28046','28090','28267','28281',
'28284','28287','28521','28527',
'28530','28533','28536','28539',
'28551','28566','28581','28584',
'28596','30199','30203','30207',
'30211','30219','30195','30331',
'30335','30323','30327','30487','30491','30507','30511','30515','30519','30523','30527','29385','4789','29346','30307','29349','30643','29331','29361','31057','31276','31279','31282','31285','31288','31294','31434','31446','31437','30523','28788','31503') AND DATE(tcs_date) = DATE(NOW())";


$query1 = mysqli_query($conn, $sql1);

       
while ($row = mysqli_fetch_array($query1))
{
    echo '<tr>
            <td>TOTAL </td>
            <td></td>

            <td>'.$row['tcsi_qty'].'</td>

        </tr>';
}

echo '




    </tbody>

</table>

</body>

</html>';



//<td>TOTAL PENGUNJUNG : '.$SQL1['tcsi_qty'].'</td>
//echo "TOTAL PENGUNJUNG :[.$query1.]";
// Apakah kita perlu menjalankan fungsi mysqli_free_result() ini? baca bagian VI
mysqli_free_result($query);

// Apakah kita perlu menjalankan fungsi mysqli_close() ini? baca bagian VI
mysqli_close($conn);

0 Response to "Coding PHP | membaca Simpel Tabel"

Post a Comment

Komentar Saudara/i sangat bermanfaat untuk membangun Blog ini,Terimakasih
Your comments are very useful for building this blog, thank you

Blog Info Teknologi