I have build a POS system on php and facing one very funny issue. I can add upto 20 items on the sale memo and it gets stored in the db and we can retrieve it and print it, but whenever I print it, it always comes out in 2 pages instead of one even if there's one item and the rest of the value is null. Is there a way to force print on one page?
Here's the code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Print Invoice - Chara Motor Servicing</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="text-center">
<h3>Chara Motor Servicing</h3>
<h4>Address Line 1</h4>
<h4>Telephone: 000000000000</h4>
<h4>GSTIN: XXXXXXXXXXXXXXX</h4>
</div>
<hr>
<?php
include 'database_connection.php';
$data=$_GET['invoice_id'];
$user_id=$data;
$sql = "SELECT `name`, `phone`, `town`, `date`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`,`item9`, `item10`, `item11`, `item12`, `item13`, `item14`, `item15`, `item16`,`item17`, `item18`, `item19`, `item20`, `item21`, `item22`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`,`q9`, `q10`, `q11`, `q12`, `q13`, `q14`, `q15`, `q16`,`q17`, `q18`, `q19`, `q20`, `q21`, `q22`, `taxper`, `amt1`, `amt2`, `amt3`, `amt4`, `amt5`, `amt6`, `amt7`, `amt8`, `amt9`, `amt10`, `amt11`, `amt12`, `amt13`, `amt14`, `amt15`, `amt16`,`amt17`, `amt18`, `amt19`, `amt20`, `amt21`, `amt22`,`taxtotal`, `subtotal`, `status` FROM `sales` WHERE id=$user_id";
$result = $conn->query($sql);
while ($row = mysqli_fetch_array($result)):
?>
<div class="row">
<div class="col-xs-12 col-md-3 col-lg-3 pull-left">
<div class="panel panel-default height">
<div class="panel-heading">Invoiced To: </div>
<div class="panel-body">
<strong><?php echo $row['name']; ?></strong><br>
<?php echo $row['phone']; ?><br>
<?php echo $row['town']; ?><br>
<?php echo $row['date']; ?><br>
<strong>Invoice#: <?php echo $user_id; ?><br> </strong>
<strong><?php echo $row['status']; ?><br> </strong><br>
<button class="btn btn-primary hidden-print" onclick="myFunction()"><span class="glyphicon glyphicon-print" aria-hidden="true"></span> Print</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="text-center"><strong>Order Summary</strong></h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<td><strong>Item Name</strong></td>
<td class="text-center"><strong>Item Quantity</strong></td>
<td class="text-right"><strong>Total Price</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row['item1']; ?></td>
<td class="text-center"><?php echo $row['q1']; ?></td>
<td class="text-right"><?php echo $row['amt1']; ?></td>
</tr>
<tr>
<td><?php echo $row['item2']; ?></td>
<td class="text-center"><?php echo $row['q2']; ?></td>
<td class="text-right"><?php echo $row['amt2']; ?></td>
</tr>
<tr>
<td><?php echo $row['item3']; ?></td>
<td class="text-center"><?php echo $row['q3']; ?></td>
<td class="text-right"><?php echo $row['amt3']; ?></td>
</tr>
<tr>
<td><?php echo $row['item4']; ?></td>
<td class="text-center"><?php echo $row['q4']; ?></td>
<td class="text-right"><?php echo $row['amt4']; ?></td>
</tr>
<tr>
<td><?php echo $row['item5']; ?></td>
<td class="text-center"><?php echo $row['q5']; ?></td>
<td class="text-right"><?php echo $row['amt5']; ?></td>
</tr>
<tr>
<td><?php echo $row['item6']; ?></td>
<td class="text-center"><?php echo $row['q6']; ?></td>
<td class="text-right"><?php echo $row['amt6']; ?></td>
</tr>
<tr>
<td><?php echo $row['item7']; ?></td>
<td class="text-center"><?php echo $row['q7']; ?></td>
<td class="text-right"><?php echo $row['amt7']; ?></td>
</tr>
<tr>
<td><?php echo $row['item8']; ?></td>
<td class="text-center"><?php echo $row['q8']; ?></td>
<td class="text-right"><?php echo $row['amt8']; ?></td>
</tr>
<tr>
<td><?php echo $row['item9']; ?></td>
<td class="text-center"><?php echo $row['q9']; ?></td>
<td class="text-right"><?php echo $row['amt9']; ?></td>
</tr>
<tr>
<td><?php echo $row['item10']; ?></td>
<td class="text-center"><?php echo $row['q10']; ?></td>
<td class="text-right"><?php echo $row['amt10']; ?></td>
</tr>
<tr>
<td><?php echo $row['item11']; ?></td>
<td class="text-center"><?php echo $row['q11']; ?></td>
<td class="text-right"><?php echo $row['amt11']; ?></td>
</tr>
<tr>
<td><?php echo $row['item12']; ?></td>
<td class="text-center"><?php echo $row['q12']; ?></td>
<td class="text-right"><?php echo $row['amt12']; ?></td>
</tr>
<tr>
<td><?php echo $row['item13']; ?></td>
<td class="text-center"><?php echo $row['q13']; ?></td>
<td class="text-right"><?php echo $row['amt13']; ?></td>
</tr>
<tr>
<td><?php echo $row['item14']; ?></td>
<td class="text-center"><?php echo $row['q14']; ?></td>
<td class="text-right"><?php echo $row['amt14']; ?></td>
</tr>
<tr>
<td><?php echo $row['item15']; ?></td>
<td class="text-center"><?php echo $row['q15']; ?></td>
<td class="text-right"><?php echo $row['amt15']; ?></td>
</tr>
<tr>
<td><?php echo $row['item16']; ?></td>
<td class="text-center"><?php echo $row['q16']; ?></td>
<td class="text-right"><?php echo $row['amt16']; ?></td>
</tr>
<tr>
<td><?php echo $row['item17']; ?></td>
<td class="text-center"><?php echo $row['q17']; ?></td>
<td class="text-right"><?php echo $row['amt17']; ?></td>
</tr>
<tr>
<td><?php echo $row['item18']; ?></td>
<td class="text-center"><?php echo $row['q18']; ?></td>
<td class="text-right"><?php echo $row['amt18']; ?></td>
</tr>
<tr>
<td><?php echo $row['item19']; ?></td>
<td class="text-center"><?php echo $row['q19']; ?></td>
<td class="text-right"><?php echo $row['amt19']; ?></td>
</tr>
<tr>
<td><?php echo $row['item20']; ?></td>
<td class="text-center"><?php echo $row['q20']; ?></td>
<td class="text-right"><?php echo $row['amt20']; ?></td>
</tr>
<tr>
<td><?php echo $row['item21']; ?></td>
<td class="text-center"><?php echo $row['q21']; ?></td>
<td class="text-right"><?php echo $row['amt21']; ?></td>
</tr>
<tr>
<td><?php echo $row['item22']; ?></td>
<td class="text-center"><?php echo $row['q22']; ?></td>
<td class="text-right"><?php echo $row['amt22']; ?></td>
</tr>
<tr>
<td class="highrow"></td>
<td class="highrow"></td>
<td class="highrow text-center"><strong>GST/Tax (%)</strong></td>
<td class="highrow text-right"><?php echo $row['taxper']; ?></td>
</tr>
<tr>
<td class="emptyrow"></td>
<td class="emptyrow"></td>
<td class="emptyrow text-center"><strong>GST/Tax Amount</strong></td>
<td class="emptyrow text-right"><?php echo $row['taxtotal']; ?></td>
</tr>
<tr>
<td class="emptyrow"></td>
<td class="emptyrow text-center"><strong>SubTotal</strong></td>
<td class="emptyrow text-right"><strong><?php echo $row['subtotal']; ?></strong></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<script>
function myFunction() {
window.print();
}
</script>
<style>
.height {
min-height: 200px;
}
.icon {
font-size: 47px;
color: #5CB85C;
}
.iconbig {
font-size: 77px;
color: #5CB85C;
}
.table > tbody > tr > .emptyrow {
border-top: none;
}
.table > thead > tr > .emptyrow {
border-bottom: none;
}
.table > tbody > tr > .highrow {
border-top: 3px solid;
}
</style>
</div>
</body>
</html>
I have table rowspan dynamic on CodeIgniter app like this :
<table>
<tr>
<td>No</td>
<td>Data</td>
<td>Data 2</td>
<td>Qty</td>
<td>Price</td>
<td>Sub Total</td>
<td>TOtal</td>
</tr>
<?php
$source1 = $this->db->query("select * from table")->result_array();
$no=1;
foreach($source1 as source1){ ?>
<tr>
<?php
$source2 = $this->db->query("select * from table where data1='$source1[data1]'");
$total_source2 = $source2->num_rows();
$source3 = $source2->result_array();
?>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $no; ?></td>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $source1['data1']; ?></td>
<?php foreach($source3 as $source3){ ?>
<td><?php echo $source3['data2'] ?></td>
<td><?php echo $source3['qty'] ?></td>
<td><?php echo $source3['price'] ?></td>
<td><?php echo $source3['sub_total'] ?></td>
<td><?php echo $source3['total'] ?></td>
</tr>
<?php } ?>
<?php $no++; } ?>
</table>
This is result of my code:
How to make it like this
?
Thanks.
This is about as efficient as anything I can come up with without the actual SQL file and I'm not sure if it works:
<table>
<tr>
<td>No</td>
<td>Data</td>
<td>Data 2</td>
<td>Qty</td>
<td>Price</td>
<td>Sub Total</td>
<td>Total</td>
</tr>
<?php
$source1 = $this->db->query("select * from table")->result_array();
$no = 1;
foreach ($source1 as $source1) {
?>
<tr>
<?php
$source2 = $this->db->query('select * from table where data1 = ' . $source1['data1']);
$total_source2 = $source2->num_rows();
$source3 = $source2->result_array();
$rowspan = true;
?>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $no; ?></td>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $source1['data1']; ?></td>
<?php foreach ($source3 as $source3) { ?>
<td><?php echo $source3['data2'] ?></td>
<td><?php echo $source3['qty'] ?></td>
<td><?php echo $source3['price'] ?></td>
<td><?php echo $source3['sub_total'] ?></td>
<?php
if ($rowspan) {
$q = $this->db->query('SELECT SUM(`sub_total`) as `nb` FROM `table` WHERE `data1` = ' . $source1['data1']);
echo "<td rowspan='{$total_source2}'>" . $q->row()->nb . '</td>';
$rowspan = false;
}
?>
</tr>
<?php } ?>
<?php
$no++;
}
?>
</table>
I have this list, but i want my own IP adres to not show in this list,
how can i make an exception? like , if (Myip = in there) { dont show}
<?php
session_start();
include_once 'dbconnect.php';
?>
<?php include ('head.php') ; ?>
<?php include ('menu.php') ; ?>
<?php if (isset($_SESSION['usr_id'])) { ?>
<?
$user_list_result = $DBcon->query("select * from users order by username ASC limit 100");
$loggedTime=strtotime('-600 seconds'); //2 minutes
$session = $_SESSION['usr_name'];
$query = $DBcon->query("SELECT * FROM users WHERE username='$session'");
$userRow=$query->fetch_array();
if ($userRow['userlevel'] > 254) {
?>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-9 well">
<div class="panel panel-default panel-compact panel-wallet">
<div class="panel-body">
<center><h1>Userlist</h1></center>
<center>
<table >
<tr> <td width="20%"><b>ID </b></td>
<td width="20%"><b>Nickname </b></td>
<td width="20%"><b>Email </b></td>
<td width="20%"><b>Status </b></td>
<td width="20%"><b>Message </b></td>
<td width="20%"><b>Click </b></td>
<td width="20%"><b>clicks </b></td>
<td width="20%"><b>credits </b></td>
<td width="20%"><b>bitcoins </b></td>
<td width="20%"><b>dogecoins </b></td>
<td width="20%"><b>dashcoins </b></td>
<td width="20%"><b>refferals </b></td>
<td width="20%"><b>ip </b></td>
<td width="20%"><b>password </b></td>
<td width="20%"><b>edit </b></td> </tr>
<?php
while($UserlistRow = $user_list_result->fetch_array())
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td></center>";?>
<td><? echo $UserlistRow[email]; ?></td>
<td><?php if($UserlistRow['onlinedate']>'$loggedTime'){ echo "<img src='images/online.jpg'/>";}else{ echo "<img src='images/offline.jpg'/>";} ?> </td>
<td>Message</td>
<td>Click</td>
<td><?php echo $UserlistRow[clicks]; ?></td>
<td><?php echo$UserlistRow[credits]; ?></td>
<td><?php echo$UserlistRow[bitcoin]; ?></td>
<td><?php echo$UserlistRow[dogecoin]; ?></td>
<td><?php echo$UserlistRow[dashcoins]; ?></td>
<td><?php echo$UserlistRow[refferals]; ?></td>
<td><?php echo$UserlistRow[ip]; ?></td>
<td><?php echo$UserlistRow[password]; ?></td>
<td><a href=admin_user_edit.php?to=<? $userRow[username] ?> class=big>Edit</a></td>
</tr>
<?php } ?> </table>
</center>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } else { include('login.php'); } ?>
<?php include ('footer.php') ; ?>
If you have a static ip then you can add a condition in the while loop as soon as it starts like,
if($ip_variable == "YOUR_IP"){
continue;
}
<?php
while($UserlistRow = $user_list_result->fetch_array())
{
if($UserlistRow[ip]!="ENTER YOUR IP HERE")
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td></center>";?>
<td><? echo $UserlistRow[email]; ?></td>
<td><?php if($UserlistRow['onlinedate']>'$loggedTime'){ echo "<img src='images/online.jpg'/>";}else{ echo "<img src='images/offline.jpg'/>";} ?> </td>
<td>Message</td>
<td>Click</td>
<td><?php echo $UserlistRow[clicks]; ?></td>
<td><?php echo$UserlistRow[credits]; ?></td>
<td><?php echo$UserlistRow[bitcoin]; ?></td>
<td><?php echo$UserlistRow[dogecoin]; ?></td>
<td><?php echo$UserlistRow[dashcoins]; ?></td>
<td><?php echo$UserlistRow[refferals]; ?></td>
<td><?php echo$UserlistRow[ip]; ?></td>
<td><?php echo$UserlistRow[password]; ?></td>
<td><a href=admin_user_edit.php?to=<? $userRow[username] ?> class=big>Edit</a></td>
</tr>
<?php }
}?>
I've a view to displaying some data from database to my php program, but the data cannot be displayed when I running it?
this is my view from phpmyadmin look like
(select `m`.`id_mutasi` AS `id_mutasi`,`m`.`tgl_mutasi` AS `tgl_mutasi`,`m`.`kode_barang` AS `kode_barang`,`a`.`nm_barang` AS `nm_barang`,`m`.`ruang_lama` AS `ruang_lama`,`m`.`ruang_baru` AS `ruang_baru`,`u`.`nm_unit` AS `unit_lama`,`m`.`unit_baru` AS `unit_baru`,`i`.`user` AS `user_lama`,`m`.`userbaru` AS `user_baru`,`m`.`jumlah` AS `jumlah`,`m`.`user_posting` AS `user_posting` from ((((((`simaset`.`mutasi` `m` join `simaset`.`inventarisasi` `i` on((`m`.`kode_inventarisasi_baru` = `i`.`kode_inventarisasi`))) join `simaset`.`aset` `a` on((`a`.`kode_barang` = `m`.`kode_barang`))) join `simaset`.`ruangan` `r` on((`r`.`kode_ruangan` = `m`.`ruang_lama`))) join `simaset`.`ruangan` `rb` on((`rb`.`kode_ruangan` = `i`.`kode_ruangan`))) join `simaset`.`unit_kerja` `u` on((`u`.`kode_unit` = `m`.`unit_lama`))) join `simaset`.`unit_kerja` `ub` on((`ub`.`kode_unit` = `i`.`kode_unit`))))
and this is my php code
<table id="table-example" class="table" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<!-- <th>NO</th> -->
<th>ID Mutasi</th>
<th>Tgl Mutasi</th>
<th>Kode Barang</th>
<th>Barang</th>
<th>Dept Lama</th>
<th>Jabatan Lama</th>
<th>Dept Baru</th>
<th>Jabatan Baru</th>
<!-- <th>User Baru</th> -->
<th>Jumlah</th>
<th>User Posting</th>
<!-- <th>User Posting</th> -->
<th>Aksi</th>
</tr>
</thead>
<tbody>
<!-- <?php $no = 1;?> -->
<?php do { ?>
<tr class=gradeX>
<!-- <td><center><?php echo $no++ ?></center></td> -->
<td><center>
<?php echo $row_rs_data['id_mutasi']; ?>
</center></td>
<td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
<td ><?php echo $row_rs_data['kode_barang']; ?></td>
<td ><?php echo $row_rs_data['nm_barang']; ?></td>
<td ><?php echo $row_rs_data['ruanglama']; ?></td>
<td ><?php echo $row_rs_data['unitlama']; ?></td>
<td ><?php echo $row_rs_data['ruangbaru']; ?></td>
<td ><?php echo $row_rs_data['unitbaru']; ?></td>
<!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
<td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
<td ><?php echo $row_rs_data['user_posting']; ?></td>
<td ><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></td>
</tr>
<?php
echo "test";
} while ($row_rs_data = mysql_fetch_assoc($rs_data)); ?>
</tbody>
</table>
Replace your <tbody> block. Use while instead of do..while and mysqli instead of mysql mysql has been deprecated.
<tbody>
<?php while ($row_rs_data = mysql_fetch_assoc($rs_data)){ ?>
<tr class=gradeX>
<!-- <td><center><?php echo $no++ ?></center></td> -->
<td><center>
<?php echo $row_rs_data['id_mutasi']; ?>
</center></td>
<td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
<td ><?php echo $row_rs_data['kode_barang']; ?></td>
<td ><?php echo $row_rs_data['nm_barang']; ?></td>
<td ><?php echo $row_rs_data['ruanglama']; ?></td>
<td ><?php echo $row_rs_data['unitlama']; ?></td>
<td ><?php echo $row_rs_data['ruangbaru']; ?></td>
<td ><?php echo $row_rs_data['unitbaru']; ?></td>
<!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
<td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
<td ><?php echo $row_rs_data['user_posting']; ?></td>
<td ><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></td>
</tr>
<?php
echo "test";
} ?>
</tbody>
I need to solve this simple thing:
Got this code:
<?php
$xml=simplexml_load_file("d2ladder.xml") or die("Error: Cannot create object");
?>
<table width="100%" border="1" cellspacing="0" cellpadding="2" align="center" style="text-align:center">
<tbody>
<tr class="<?php if ($xml->ladder[12]->char[0]->status == "alive") { echo "alive"; } else { echo "dead"; } ?>">
<td width="10%">1.</td>
<td width="50%" style="text-align:left"><?php echo $xml->ladder[12]->char[0]->prefix; ?> <?php echo $xml->ladder[12]->char[0]->name; ?></td>
<td width="10%"><?php echo $xml->ladder[12]->char[0]->class; ?></td>
<td width="10%"><?php echo $xml->ladder[12]->char[0]->level; ?></td>
<td width="20%"><?php echo $xml->ladder[12]->char[0]->experience; ?></td>
</tr>
<tr class="<?php if ($xml->ladder[12]->char[1]->status == "alive") { echo "alive"; } else { echo "dead"; } ?>">
<td width="10%">2.</td>
<td width="50%" style="text-align:left"><?php echo $xml->ladder[12]->char[1]->prefix; ?> <?php echo $xml->ladder[12]->char[1]->name; ?></td>
<td width="10%"><?php echo $xml->ladder[12]->char[1]->class; ?></td>
<td width="10%"><?php echo $xml->ladder[12]->char[1]->level; ?></td>
<td width="20%"><?php echo $xml->ladder[12]->char[1]->experience; ?></td>
</tr>
</tbody>
</table>
Need to create rows on this table till char[99]
Maybe I need to use while? Because sometimes it wont get to 99 on the sitemap
Use for/while cycle:
for ($i = 0; $i < 100; $i++) {
?>
<tr class="<?php if ($xml->ladder[12]->char[$i]->status == "alive") { echo "alive"; } else { echo "dead"; } ?>">
<td width="10%"><?php echo $i; ?>.</td>
<td width="50%" style="text-align:left"><?php echo $xml->ladder[12]->char[$i]->prefix; ?> <?php echo $xml->ladder[12]->char[$i]->name; ?></td>
<td width="10%"><?php echo $xml->ladder[12]->char[$i]->class; ?></td>
<td width="10%"><?php echo $xml->ladder[12]->char[$i]->level; ?></td>
<td width="20%"><?php echo $xml->ladder[12]->char[$i]->experience; ?></td>
</tr>
<?php }
See for cycle
Hope this helps.