How to make repeat table on each page and sum of the column only shown on last page. I want to make something like this.
PAGE I
---------------------------
| no | item | qty |
---------------------------
| 1 | Item 1 | 2 |
| 2 | Item 2 | 2 |
| 3 | Item 3 | 3 |
.........
| 20 | Item 20 | 1 |
---------------------------
| TOTAL | |
---------------------------
PAGE 2
---------------------------
| no | item | qty |
---------------------------
| 21 | Item 21 | 2 |
| 22 | Item 22 | 2 |
| 23 | Item 23 | 3 |
.........
| 40 | Item 40 | 1 |
---------------------------
| TOTAL | 50 |
---------------------------
As you can see, i need to show exact table design on each page and each page limit with 20 item only, and sum of the qty shown on last page.
this is i have been working on
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style type="text/css">
#media print
{
#printbtn {display: none;}
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
#media screen
{
thead { display: block; }
tfoot { display: block; position: fixed; }
}
</style>
<script type="text/javascript">
function printDiv(divID) {
var divElements = document.getElementById(divID).innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
window.print();
document.body.innerHTML = oldPage;
}
</script>
</head>
<body>
<input type="button" value="print" onclick="javascript:printDiv('tabel');">
<div id="tabel">
<table width="1200" border=0>
<caption>table title and/or explanatory text</caption>
<thead>
<tr>
<td>No.</td>
<td>Headerrr</td>
</tr>
</thead>
<tfoot>
<tr>
<td>This is Footer</td>
<td>this is footer too</td>
</tr>
</tfoot>
<tbody>
<?
$x=1;
for($x=1;$x<=500;$x++)
{
?>
<tr>
<td><?echo $x;?></td>
<td><?echo "Data ".$x;?></td>
</tr>
<?
}
?>
</tbody>
</table>
</div>
</body>
</html>
This is very important to my job. I really appreciate any suggest. Thank you.
Related
I have a table name "scores"
+----+-------+-------+-------------------+
| id | score | level | username |
+----+-------+-------+-------------------+
| 1 | 65 | one | dustyrydberg |
| 2 | 56 | one | dustyrydberg |
| 3 | 34 | one | pointedshrill |
| 4 | 50 | one | witchrage |
| 5 | 41 | one | spacetimeken |
| 6 | 44 | one | harperhetton |
| 7 | 65 | one | witchrage |
| 8 | 70 | one | paladino |
| 9 | 50 | one | chimpanzer |
| 10 | 22 | one | yahooligan |
| 11 | 672 | one | blueCrow |
| 12 | 120 | one | sleepyDolphin |
| 13 | 43 | one | gothicNightingale |
| 14 | 22 | one | phonyPuppy |
| 15 | 23 | one | phonyPuppy |
| 16 | 24 | one | phonyPuppy |
| 17 | 31 | one | darlingFairy |
| 18 | 36 | one | starkVoid |
+----+-------+-------+-------------------+
I am trying to list the top 10 highscores without duplication of usernames. I am doing this using php and mysql. I have a functions.php file which includes the following function:
function find_all_scores() {
global $connection;
$query = "SELECT MIN(score), username ";
$query .= "FROM scores ";
$query .= "GROUP BY username ";
$query .= "ORDER BY MIN(score) ASC";
$score_set = mysqli_query($connection, $query);
confirm_query($score_set);
return $score_set;
}
Which is called on in the all_highscores.php file
<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/db_connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php
$score_set = find_all_scores();
$ranking = 1;
?>
<?php $layout_context = "score"; ?>
<?php include("../includes/layouts/header.php"); ?>
<div id="main">
<div id="navigation">
</div>
<div id="page">
<?php echo message(); ?>
<h2>Your Highscores</h2>
<p>Here are <?php echo htmlentities($_SESSION["username"]); ?>'s best scores.</p>
<table>
<tr>
<th style="text-align: left; width: 200px;">Position</th>
<th style="text-align: left; width: 200px;">Username</th>
<th style="text-align: left; width: 200px;">Level</th>
<th colspan="2" style="text-align: left;">Score</th>
</tr>
<?php while($score = mysqli_fetch_assoc($score_set)) { ?>
<tr>
<td><?php echo $ranking; ?></td>
<td><?php echo htmlentities($score["username"]); ?></td>
<td><?php echo htmlentities($score["level"]); ?></td>
<td><?php echo htmlentities($score["score"]); ?></td>
<?php
$ranking = $ranking + 1; /* INCREMENT RANKING BY 1 */
?>
</tr>
<?php } ?>
</table>
</div>
</div>
<?php
// 4. Release returned data
//mysqli_free_result($result);
?>
<?php include("../includes/layouts/footer.php"); ?>
However I keep ending up with either a query failure or nothing displays in the HTML browser. Please help!
I finished my studies but now I need to develop a project and I thought about creating a web app for a gym, but I'm stuck on the schedule module. I need it to get the info from a database like this:
+--------+------------+--------+----------+------+-----------+------------+
| ID_Act | HoraInicio | Dia | Duracion | Sala | DNI_Prof | Dificultad |
+--------+------------+--------+----------+------+-----------+------------+
| 1 | 09:00:00 | LUNES | 45 | 1 | 12345678A | 2 |
| 1 | 09:00:00 | MARTES | 45 | 1 | 12345678A | 3 |
| 1 | 10:30:00 | LUNES | 45 | 1 | 12345678A | 1 |
+--------+------------+--------+----------+------+-----------+------------+
ID_Act: Activity ID
HoraInicio: Start time
Dia: Day
Duración: Duration
Sala: Room
DNI_Prof: Teacher ID
Dificultad: Level
I've been trying to create the whole schedule using a for loop so I don't have to copy&paste 50 rows. I can create the whole schedule with the loop but I can not print the values that I need to have in the proper cell.
This is the code of what I've been trying:
<?php session_start(); ?>
<?php
include("connbd.php");
$consulta="SELECT actividades.nombre AS Actividad, ID_Act, HoraInicio, Dia, Duracion, Sala, Dificultad FROM horarios
JOIN actividades WHERE actividades.id LIKE ID_Act;";
$resultado=mysqli_query($conn,$consulta);
$hora = array("09:00","09:15","09:30","09:45","10:00","10:15","10:30","10:45","11:00","11:15","11:30",
"11:45","12:00","12:15","12:30","12:45","13:00","13:15","13:30","13:45","14:00","14:15","14:30","14:45",
"15:00","15:15","15:30","15:45","16:00","16:15","16:30","16:45","17:00","17:15","17:30","17:45","18:00",
"18:15","18:30","18:45","19:00","19:15","19:30","19:45","20:00","20:15","20:30","20:45","21:00");
?>
<div id=contenidoHorarios class="contenidoHorarios">
<div id=contenidoHorariosTabla class="contenidoHorariosTabla">
<div id=contenidoHorariosTablaHoras class="contenidoHorariosTablaHoras">
<table border="1px" id="contenidoHorariosTablaTabla" class="contenidoHorariosTablaTabla">
<tr>
<th width="5%"></th>
<th width="13.57%">Lunes</th>
<th width="13.57%">Martes</th>
<th width="13.57%">Miércoles</th>
<th width="13.57%">Jueves</th>
<th width="13.57%">Viernes</th>
<th width="13.57%">Sábado</th>
<th width="13.57%">Domingo</th>
</tr>
<?php
foreach ($hora as $horatupla) {
?>
<tr>
<th><?php echo $horatupla; ?></th>
<td id="<?php
while ($row=$resultado->fetch_assoc())
{
$id = $row['ID_Act'];
$horainicio = substr($row['HoraInicio'],0,-3);
$dia = $row['Dia'];
$duracion = $row['Duracion'];
$sala = $row['Sala'];
$dificultad = $row['Dificultad'];
$actividad = $row['Actividad'];
if($dia=='LUNES'){echo $dia . $horatupla;} ?>" rowspan="<?php if($duracion=='15' || $duracion==''){echo '1';} if($duracion=='30'){echo '2';} if($duracion=='45'){echo '3';} ?>"
<?php
if ($horatupla==$horainicio)
{
echo $actividad;
}
}
?>>
</td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
I hope you understand what I'm saying, but to help you, I give you a example of what I do want to do (no spam).
http://www.go-fit.es/Horarios/Index
There is a text field and a table. If we put a value in that text field the corresponding name needs to be displayed on the table from data base:
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<center><table>
<tr><td>no</td><td><input type="text" name="no" autofocus></td></tr>
</table></center>
<br>
<br>
<center>
<table cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999">
<thead>
<tr>
<th> Element_Number</th>
</tr>
</thead>
<?php
if(isset($_POST['no']))
{
$c=mysql_connect("localhost","root","");
mysql_select_db("test");
if(!$c)
{
echo "db prob".mysql_error();
}
$no=$_POST['no'];
$qry=mysql_query("select name from opt where no='$no'");
if(!$qry)
{
echo "ret".mysql_error();
}
if(mysql_num_rows($qry)!=0)
{
$row=mysql_fetch_array($qry);
$name=$row['name'];
}
else
{
echo "query Invalid";
}
echo "<td>" .$name."</td></tr>" ;
}
?>
when I tried this code output like this-->
no--001
|element no |
| aaa |
no--002
|element no |
| bbb |
what I want to do to get an output like this--->
no--001
|element no |
| aaa |
no--002
|element no |
| aaa |
| bbb |
no--003
|element no |
| aaa |
| bbb |
| ccc |
I have problems when numbering the tables using CodeIgniter framework with libraary pagination. below are the table..
+------------------------------------------+
| num| NIP | Name | Category | Type |
+------------------------------------------+
| 1 | 12345 | udin | A | A1 |
+------------------------------------------+
| | | | B | B1 |
+------------------------------------------+
| | | | C | C1 |
+------------------------------------------+
| 2 | 54321 | JHON | B | B2 |
+------------------------------------------+
| | | | C | C1 |
+------------------------------------------+
the issue is on the next page in the table below..
+------------------------------------------+
| num| NIP | Name | Category | Type |
+------------------------------------------+
| 1 | 54321 | JHON | F | F2 |
+------------------------------------------+
| | | | G | G3 |
+------------------------------------------+
| | | | G | G4 |
+------------------------------------------+
| | | | I | I3 |
+------------------------------------------+
| | | | J | J1 |
+------------------------------------------+
I want the next page numbering sequential numbering starting from the end of the previous value. Supposedly in figure 2 numbering number "2" instead of "1".
code in the controller:
$this->load->library('pagination');
$data['judul'] = 'Report Data Attachment';
$start_row = $this->uri->segment(3);
$per_page = 10;
if (trim($this->uri->segment(3)) == '')
{
$start_row = '0';
}
$config['base_url'] = base_url().'report/index/';
$config['total_rows'] = $this->lampiran_m->lampiran_karyawan_semua_page_conter()->num_rows();
//$config['uri_segment'] = '3';
$config['per_page'] = $per_page;
$config['full_tag_open'] = '<p class="page">';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['lampiran'] = $this->lampiran_m->lampiran_karyawan_semua_page($start_row,','.$per_page);
$data['no'] = '';
$data['last'] = '';
$this->template->display('tabel_report',$data);
and code in my Model :
public function lampiran_karyawan_semua_page($offset='',$limit='')
{
$qry = "select distinct lampiran.id_category,name_category,tipe,lampiran.nip from lampiran
left join employee on (lampiran.nip = employee.nip)
left join category on (lampiran.id_category=category.id_category) where lampiran.id_category = category.id_category and lampiran.nip=employee.nip order by lampiran.nip desc limit $offset $limit";
return $this->db->query($qry);
}
and this code in view :
<table border="1" width="100%" cellpadding="0" cellspacing="0" id="product-table" >
<tr>
<th class="table-header-repeat line-left minwidth-1"> No</th>
<th class="table-header-repeat line-left minwidth-1"> NIP</th>
<th class="table-header-repeat line-left minwidth-1"> Name</th>
<th class="table-header-repeat line-left minwidth-1"> Category Attachment</th>
<th class="table-header-repeat line-left minwidth-1">Type Attachment </th>
<th class="table-header-repeat line-left minwidth-1">Page </th>
</tr>
<?php
foreach($lampiran->result_array() as $k) {
$now=$k['nip'];
if($last!=$now ) {
$no++;
echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}else{
echo "<tr><td> </td><td> </td><td> </td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}
$last = $k['nip'];
}
?>
<tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
<?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
<?php echo "<b>$row->jumlah</b>";?>
<?php endforeach; ?>
</td></tr>
</table>
I hope someone can help me on this issue .. thanks
before foreach you have to add
$no = $this->uri->segment(3)+1;
No
NIP
Name
Category Attachment
Type Attachment
Page
</tr>
<?php
//before foreach you have to add
$no = $this->uri->segment(3)+1;
foreach($lampiran->result_array() as $k) {
$now=$k['nip'];
if($last!=$now ) {
$no++;
echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}else{
echo "<tr><td> </td><td> </td><td> </td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}
$last = $k['nip'];
}
?>
<tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
<?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
<?php echo "<b>$row->jumlah</b>";?>
<?php endforeach; ?>
</td></tr>
</table>
please put below line before foreach statement
$currentffset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$slno_start = (($currentffset / $per_page) * per_page) + 1;
after that use $slno_start as serial number for each item inside foreach at last line of foreach just increment it
$slno_start++;
Minor improvement from above answers.Thanks both of u guys
$count =$this->uri->segment(3)+1;
foreach($records as $rec){echo $count; $count++;}
Sorry about the length here. I'm using oscommerce and have a page with all our product specials laid out in a 3 column table. I need to align the price of each product so that all the prices align across the screen with one another.
Visually, this is what I would like:
|-----------------------|
| Image | Image | Image |
| Title | Long | Very, |
| | Title | very, |
| | | long |
| | | title |
|$19.99 |$29.99 |$139.00|
|-----------------------|
Currently, this is what the existing code generates:
|-----------------------|
| Image | Image | Image |
| Title | Long | Very, |
| $19.99| Title | very, |
| |$29.99 | long |
| | | title |
| | |$139.00|
|-----------------------|
This is the code as it stands:
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<?php
$column = 0;
$specials_query = tep_db_query($specials_split->sql_query);
while ($specials = tep_db_fetch_array($specials_query)) {
$column ++;
echo '<td align="center" width="33%" class="productListing-data" valign="top">
<div class="prodimagebox"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO,
'products_id=' . $specials['products_id']) . '">' . tep_image(DIR_WS_IMAGES .
$specials['products_image'], $specials['products_name'], SMALL_IMAGE_WIDTH,
SMALL_IMAGE_HEIGHT) . '</a></div><br><a href="' .
tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id'])
. '">' . $specials['products_name'] . '</a><br>'
. $currencies->display_price($specials['specials_new_products_price'],
tep_get_tax_rate($specials['products_tax_class_id'])) . '</td>' . "\n";
if ((($column / 3) == floor($column / 3))) {
?>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<?php
}
}
?>
</tr>
</table>
I was trying to write some code that writes out the image and title, then takes us back 3 steps in the array. Next a new row, then three new columns containing the prices for the products above, a separator, and then continue on from there.
This way the prices would all be vertically aligned with one another, no matter the size of the title. I was heading down the pass of multiple nested loops and still getting no closer to my final result.
Help would be greatly appreciated.
you should put the description and the price into two different divs:
<style>
td.productListing-data div.item_wrapper {
position: relative;
}
td.productListing-data div.item_wrapper div.item_description {
margin-bottom: 15px;
}
td.productListing-data div.item_wrapper div.item_price {
position: absolute;
bottom: 0;
height: 15px;
}
</style>
<td align="center" width="33%" class="productListing-data" valign="top">
<div class="item_wrapper">
<div class="item_description">
<!-- the description -->
</div>
<div class="item_price">
<!-- the price -->
</div>
</div>
</td>
I have just created an example, all you need to do is to work it into your table creation.