Displaying message outside of while loop - php

I have some working code where a directory is scanned and the PDF file results placed in a table. However, what I cannot seem to do is if there are no results then display a message in the table outside the while loop. Can someone help with this. Thanks
<?php
// WHAT IS IN THE STORAGE DIRECTORY
$sub = 'destcerts' . '/' . $_SESSION['kt_idcode_usr'];
// READ THE NAMES OF FILES IN THE SUB-DIRECTORY
$fff = new DirectoryIterator($sub);
$sss = array();
foreach ($fff as $filedata)
{
// SKIP THE "DOT" FILES
if ($filedata->isDot()) continue;
// ACTIVATE THIS LINE TO RESTRICT IT TO PDF FILES ONLY
if ($filedata->getExtension() != 'pdf') continue;
// CREATE LINKS TO THESE FILES
$nom = $filedata->getFilename();
$value = substr ($nom, 0, 4);
//$_SESSION['value'] = $value;
if($_SESSION['kt_idcode_usr'] == $value) {
$lnk
= '<img src="destcerts/PDF_icon_100.png" style="margin-bottom: 15px; margin-top:15px;"><br /><a href="'
. $sub
. '/'
. $nom
. '" style="color:#0099FF; text-decoration:none; font-size:12px; font-family: Verdana, Geneva, sans-serif;">'
. $nom
. '</a>'
;
}
// COLLECT THE LINKS HERE
$sss[] = $lnk;
}
// ACCUMULATE THE TABLE ROWS HERE
$trs = NULL;
// COLLECT GROUPS OF FOUR
while (!empty($sss))
{
$td1 = array_shift($sss) or NULL;
$td2 = array_shift($sss) or NULL;
$td3 = array_shift($sss) or NULL;
$td4 = array_shift($sss) or NULL;
// USE HEREDOC TO INSERT THESE INTO A TABLE ROW
$tr = <<<EOD
<tr>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td1</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td2</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td3</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td4</td>
</tr>
EOD;
// APPEND THE TABLE ROW TO THE OTHER ROWS
$trs .= $tr;
}
// USE HEREDOC TO INSERT THE TABLE ROWS INTO THE TABLE
$tab = <<<EOD
<table id="pdfDownload" width="94%" align="center" border="1" cellspacing="10" cellpadding="0" style="border:1px solid grey; padding-bottom: 10px; margin-bottom:20px;">
<th style="text-align:center; padding: 10px !important; padding-bottom: 20px; border:1px solid black; background-color: #3399FF; color: white; font-size: 18px !important;" colspan="4">Destruction Certificates Download</th>
<tr>
<th style="text-align:center; padding-top: 10px !important;"></th>
<th></th>
<th></th>
<th></th>
</tr>
$trs
</table>
EOD;
// SHOW THE WORK PRODUCT
echo $tab;
?>

Try enclosing the WHILE LOOP in a IF statement to verify if there is anything to loop.
If(!empty($sss)){
while (!empty($sss))
{
$td1 = array_shift($sss) or NULL;
$td2 = array_shift($sss) or NULL;
$td3 = array_shift($sss) or NULL;
$td4 = array_shift($sss) or NULL;
// USE HEREDOC TO INSERT THESE INTO A TABLE ROW
$tr = <<<EOD
<tr>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td1</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td2</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td3</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td4</td>
</tr>
EOD;
// APPEND THE TABLE ROW TO THE OTHER ROWS
$trs .= $tr;
}
}
else{
$msg = " Put some message to display that there are no files to display ";
$tr = <<<EOD
<tr>
<td align="center" colspan="4" style="padding-bottom:20px !important;">$msg</td>
</tr>
EOD;
$trs .= $tr;
}

Related

TCPDF table header automatically move to the right

I have created a table with TCPDF. The header, which has a black background, has been positioned slightly to the right as though there is some padding on the left hand side. I cannot get it to line up correctly.
The code below is the HTML I have written to form the table.
$tbl ='<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
<th width="1px"></th>
<th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;"> <strong>Product or Service</strong></th>
<th width="1px"></th>
<th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
<th width="1px"></th>
<th width="84px"><strong>Total</strong></th>
</tr>
<tr>
<td height="267px">';
while($i <= $a) {
$tbl .= '<table height="267px" width="60px"><tr><td>' . $productsArray['product_quantity'][$i] . '</td></tr></table>';
$i++;
}
$tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($j <= $a) {
$tbl .= '<table height="267px" width="388px"><tr><td class="tal"> ' . $productsArray['product_name'][$j] . '</td></tr></table>';
$j++;
}
$tbl .= '</td><td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($k <= $a) {
$tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_price'][$k] . '</td></tr></table>';
$k++;
}
$tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($l <= $a) {
$tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_sub'][$l] . '</td></tr></table>';
$l++;
}
$tbl .= '</td>
</tr>
</table>';
}
The below code is the PHP I have used to show the table on the page.
$pdf->writeHTMLCell(175, 80, 20, 100, $tbl, 1, 1, 0, true, 'C', true);
Using tables within cells of another table is generally a really bad idea and is likely contributing to the problem you are having. Since it looks like your productsArray already has all of the data you need I would simply loop through it outputting each row as you go.
It's also worth pointing out that the empty header rows that are defined with a width of 1px conflict with your actual data rows which are defined with a width of 0.5px.
<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
<th width="1px"></th>
<th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;"> <strong>Product or Service</strong></th>
<th width="1px"></th>
<th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
<th width="1px"></th>
<th width="84px"><strong>Total</strong></th>
</tr>
<?php
while($i <= $a) {
?>
<tr>
<td height="267px"><?php echo $productsArray['product_quantity'][$i]; ?></td>
<td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_name'][$i]; ?></td>
<td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_price'][$i]; ?></td>
<td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_sub'][$l]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>

How to create horizontal scroller inside table?

I have create a table where I have retrieve data from database and put into table. I have a column in my database which is duration. for example duration is 10 so, number of weeks are week1,week2,week3 and so on in the table format. Now, I want to give horizontal scroller of weeks. So, How can I do this ?Please help me.
code:
<table class="table table-bordered">
<thead>
<th>A1</th>
<th>A2</th>
<th>A3</th>
<th>A4</th>
<?php
foreach ($prop as $row)
{
$duration = $row['duration'];
for($i=1; $i<=$duration; $i++)
{
echo "<th>week".$i."</th>";
}
}
?>
<th>A5</th>
<th>Total</th>
</thead>
<tbody>
<?php
foreach ($prop as $row)
{
$duration = $row['duration'];
$role = explode(",", $row['role']);
foreach ($role as $key)
{
$this->db->select('*');
$this->db->from('designation_master');
$where = "id = '".$key."'";
$this->db->where($where);
$sql = $this->db->get();
$res = $sql->result_array();
foreach ($res as $rows)
{
$rol = $rows['designation_name'];
}
?>
<tr>
<td id="s-some"><?php echo $rol; ?></td>
<td id="s-some"></td>
<td id="s-some"></td>
<td id="s-some"></td>
<?php
$duration = $row['duration'];
for($i=1; $i<=$duration; $i++)
{
echo "<td>
<input type='text' name='a' id='a".$i."' style='width: 40px;'/>
</td>";
}
?>
<td id="s-some"></td>
<td id="s-some"></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
Thank You
You can make a holder for your table. and place your table inside.
Use overflow and place the table inside an holder. You can check the code below for reference.
.table-box{
max-width: 100px;
overflow-x: scroll;
}
.table-holder{
overflow: hidden;
}
/* Not important -> table styling */
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
<div class="table-holder">
<div class="table-box">
<table >
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
</div>
</div>

generating data from db in tcpdf table

I am trying to generate pdf with database values using tcpdf.
I have a function to fetch data like this
function fetch_data()
{
$output = '';
include('../connection.php');
// Colors, line width and bold font
//My sql
$sql ="";
$query = mysqli_query($con, $sql) or die (mysqli_error($con));
$total_amt = 0;
$tax_amt = 0;
while($row = mysqli_fetch_array($query)) {
$output .= '<tr>
<td style="border-bottom:1px thin #666; font-size:12px; font-weight:normal; font-style:normal;">'.$row["product"].' - '.$row['description'].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["uom"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["price"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["qty"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["discount"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["taxation"].'%</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["total"].'</td>
</tr>
';
$total_amt += $row['total'];
$tax_amt += $row['tax_amount'];
}
$output .= '<tr><td colspan="7" style="border-top:1px thin #666";></td></tr><tr><td colspan="5" align="left"><strong>Total</strong></td><td align="center">'.number_format($tax_amt,2).'</td><td align="center">'.number_format($total_amt,2).'</td></tr>';
return $output;
}
And i display it
$content = '';
$content .= '
<table border="1"><tr><td width="100%">
<table border="0">
<tr bgcolor="#796799" style="color:#FFF;">' ;
$pdf->SetFont('arsenalb', 'B', 12);
$content .= '
<th width="40%" style="border-left-width:14px;border-left-color:#796799;" height="30" align="center">Description</th>
<th width="10%" align="center">UOM</th>
<th width="13%" align="center">Price</th>
<th width="7%" align="center">Qty</th>
<th width="7%" align="center">Disc</th>
<th width="10%" align="center">Tax</th>
<th width="13%" align="center">Total</th>
</tr>
';
$pdf->SetFont('arsenal', '', 10);
$content .= fetch_data();
$content .= '</table></td></tr></table>';
$pdf->writeHTML($content);
I want only the table headers to be bold, so i have used $pdf->SetFont('arsenal', '', 10); after the header . But it is making the header also normal, not bold. if i remove this, then whole table data is becoming bold.
is there any way to separate the table something like this? https://tcpdf.org/examples/example_011/
The reason this wont work is quite simpel. You write all $content to the $pdf AFTER the second SetFont line. Meaning that the first line is used, but since no content is added to the pdf, it wont show anything.
Since tcpdf allows you to write HTML, wyy not use HTML to make the header bold? with the <b> tag. Another option is that you make two tables. One for the header and one for the content. Since you define the width of the columns, you can do this.
You'll get something like:
$hdr = 'full table with header data';
$pdf->SetFont('arsenalb', 'B', 12);
$pdf->writeHTML($hdr);
$content .= 'new table, with column with defined';
$content .= fetch_data();
$content .= '</table></td></tr></table>';
$pdf->SetFont('arsenal', '', 10);
$pdf->writeHTML($content);
but that might work depending on if you need that second outer table. If you need it, it will most likely not possilbe, unless you can write partial HTML yo $pdf->writeHTML(). I'm not sure you can/cannot.

In TCPDF how to tell if my table will be bigger than the page because in this case I would have to add a custom header for it

In TCPDF how can I tell if my table will be bigger than the page because in this case I would have to add a custom header for it. If I use $pdf->getAliasNumPage() to compare before I start the table and at the beginning of each row don't seem to work. $pdf->getAliasNumPage() if used second time return something like {:pnp:}
my code looks like this:
$table="";
$islasttable = 0;
for ($i = 0; $i<sizeof($ar); $i++) {
for ($j = 0; $j<3; $j++) {
if (isset ($ar[$i][$j])) {
if ($j == 0) {
if ($islasttable == 1) {
$table .= '</table><table border="1" style="text-align:center; vertical-align:middle; padding:5;border-bottopm:1px solid black;">';
$islasttable = 0;
} else {
$table .= '<table border="1" style="text-align:center; vertical-align:middle; padding:5;">';
}
$table .= '<tr>
<td colspan="3">Gefehrdungsfaktor</td>
<td colspan="8">'.$ar[$i][$j].'</td>
</tr>';
}
if ($j == 1) {
$table .= ' <tr >
<td colspan="3">gefahrebquelle</td>
<td colspan="8">'.$ar[$i][$j].'</td>
</tr>';
$flag = 1;
}
if ($j == 2) {
if ($flag == 1) {
$level = " top level2 with: ".$ArrayToGenerateTable[$i].' childs';
$table.='<tr>
<td colspan="11">Risiko</td>
</tr>';
$table.='<tr >
<td colspan="1" style="font-size: xx-small; background-color:#F3A505">GK </td>
<td colspan="5" style="background-color:#F3A505">(n)</td>
<td colspan="2" style="background-color:#F3A505"> ?</td>
<td colspan="2" style="background-color:#F3A505"></td>
<td colspan="1" style="font-size: xx-small; background-color:#F3A505">GK </td>
</tr>';
$table.='<tr >
<td colspan="1" rowspan="'.(($ArrayToGenerateTable[$i])*2).'" style="background-color:grey">0</td>
<td colspan="5" rowspan="2">'.$ar[$i][$j].'</td>
<td colspan="1" rowspan="1">ja</td>
<td colspan="1" rowspan="1">X</td>
<td colspan="2" rowspan="2"> </td>
<td colspan="1" rowspan="'.(($ArrayToGenerateTable[$i])*2).'" style="background-color:grey;">0</td>
</tr>
<tr >
<td colspan="1">nein'.'</td>
<td colspan="1">X</td>
</tr>';
} else {
$table.='<tr >
<td colspan="5" rowspan="2">'.$ar[$i][$j].'</td>
<td colspan="1">ja</td>
<td colspan="1">X</td>
<td colspan="2" rowspan="2"> </td>
</tr>
<tr >
<td>nein</td>
<td>X</td>
</tr>';
}
$level = '';
$flag=0;
$islasttable = 1;
}
}
}
}
$table.='</table>';
$pdf->AddPage();
$pdf->writeHTML($table, true, false, true, false, '');
One solution I have:
<style>
table{
table-layout: fixed;
}
td{
max-height:20px;
}
</style>
and with this I can calculate the number of lines.

pagination - not working

I don't understand why my pagination is not working! It is displaying ok by default, but When click on 'Next' page or some page number nothing happens, not changing page at all. It's like not recognizing pagination.js or pagination_class.php.
I have another part of site where it is working fine, so not sure did I miss something obvious here?
In same folder have 4 files concerning this:myaccount_betinghistory.php, myaccount_bettinghistory_sub.php, pagination.js, pagination_class.php.
Here are all the codes of those files to have everything to look in, I hope you will be able to find bug there!
myaccount_bettinghistory.php:
<?php
error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');
?>
<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<?PHP
//Session start
#session_start();
//Path to root
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
//Require Init
$mode = array();
$mode[] = 'nohtml';
require_once $root . "/inc/php/init.php";
{
?>
<?PHP
}
?>
<?
$qry = "
SELECT timelive,bidprice,match_title,selection,winnings_with_startamount,odds,odds*10 AS gainedodds,username,
CASE
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status LIKE 'E' THEN 'pending'
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status NOT LIKE 'E' THEN 'active'
WHEN each_bid_recorded_Part2.result liKE each_bid_recorded_Part2.selection THEN 'WON'
WHEN each_bid_recorded_Part2.result NOT liKE each_bid_recorded_Part2.selection THEN 'LOST'
END AS result
FROM each_bid_recorded_Part2 WHERE each_bid_recorded_Part2.username LIKE '" . $_SESSION['username'] . "'
";
$qry .= " ORDER BY timelive DESC";
//for pagination
$starting=0;
$recpage = 4;//number of records per page
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
function getStyleColorForStatus($status) {
if ($status == 'WON') {
return '#99ff99';
}
else if ($status == 'LOST') {
return '#ff9999';
}
else if ($status == 'pending') {
return '#e5e5e5';
}
else if ($status == 'active') {
return '#ffffcc';
}
return '';
}
?>
<div>
<div class="pageTop"><img src="images/icons/faqicon.png" width="37" height="37" align=absbottom> Betting History</div>
<tr>
<td> </td>
</tr>
</div>
<div>
<p style="font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #535252; text-align: left;">Check your bets with you as a last bidder.</p>
</div>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-size:11px; color: #535252;">
<form name="form1" action="myaccount_bettinghistory.php" method="POST" style="background-color:#f9f9f9; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1);">
<table border="0" align="left" width="500px" padding-left="0px" style="background:#F9F9F9;">
<tr><TD colspan="0">
<div id="page_contents">
<table width="755px" cellspacing="0" cellpadding="5" align="center" frame="box" rules="none" style="padding-bottom:2px; margin-bottom:0px; margin-top:3px; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1); border: 1px solid #cccccc;">
<tr style="height: 40px;">
<td width="30%" align="center" td class="winheader"><div class="glowtext">Event Start Time</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Bid Cost</div></td></td>
<td width="35%" align="center" td class="winheader"><div class="glowtext">Market/Event</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Selection</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winnings</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Odds</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Gained Odds</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winning Bidder</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Final Result</div></td></td>
</tr>
<?if(mysql_num_rows($result)!=0){
$counter = $starting + 1;
while($data = mysql_fetch_array($result)) {?>
<tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
<td align="center"><font color="#333"><? echo $data['timelive']; ?></TD>
<td align="center">€ <? echo $data['bidprice']; ?></TD>
<td align="left"><font color="#0070c0"><? echo $data['match_title']; ?></TD>
<td align="left"><? echo $data['selection']; ?></TD>
<td align="center"><font color="green">€ <? echo $data['winnings_with_startamount']; ?></TD>
<td align="center"><? echo $data['odds']; ?></TD>
<td align="center"><? echo $data['gainedodds']; ?></TD>
<td align="center"><? echo $data['username']; ?></TD>
<td align="center" style="background-color:<?php echo getStyleColorForStatus($data['result']); ?>"><? echo $data['result']; ?></td>
</tr>
<?
$counter ++;
} ?>
<tr><TD align="center" colspan="10" style="padding-bottom:1px; padding-top:10px; color:#333;"><? echo $obj->anchors; ?></TD></tr>
<tr><TD align="center" colspan="10" style="padding-bottom:10px; padding-top:5px; color:#333;"><? echo $obj->total; ?></TD></tr>
<?}else{?>
<tr><TD align="center" colspan="10" style="padding-bottom:10px padding-top:10px; color:red;">No Data Found</TD></tr>
<?}?>
</TD></tr>
</table>
</div>
</tr>
</TD>
</form>
</table>
<STYLE>
*{ margin-bottom:0; }
#pagination-flickr li{
margin:0px;
padding:0px;
float:left;
font-size:10px;
}
#pagination-flickr a{
float:left;
padding:5px 7px;
margin-right:5px;
border:solid 1px #4d7dc5;
text-decoration:none;
background:#FFFFFF;
color:#4d7dc5;
font-size:10px;
}
#pagination-flickr .previous-off,
#pagination-flickr .next-off {
border:solid 1px #DDDDDD;
cursor:default;
background:#FFFFFF;
border:solid 1px #BBBBBB;
color:#BBBBBB;
padding:4px 6px;
margin-right:5px;
font-size:10px;
}
#pagination-flickr .next a,
#pagination-flickr .previous a {
background:#FFFFFF;
border:solid 1px #BBBBBB;
color:#BBBBBB;
font-size:10px;
}
#pagination-flickr .active{
cursor:default;
background:#4d7dc5;
color:#FFFFFF;
padding:4px 6px;
margin-right:5px;
border:solid 1px #4d7dc5;
font-size:10px;
}
#pagination-flickr a:link,
#pagination-flickr a:visited {
padding:4px 6px;
margin-right:5px;
border:solid 1px #4d7dc5;
background:#FFFFFF;
color:#4d7dc5;
font-size:10px;
}
#pagination-flickr a:hover{
padding:4px 6px;
margin-right:5px;
border:solid 1px #4d7dc5;
background:#ffc04a;
color:#000;
font-size:10px;
}
body,table
{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
padding-bottom:5px;
empty-cells: show;
}
.glowtext
{
text-shadow: 0 0 20px white;
color:#333;
font-weight:bold;
}
</STYLE>
myaccount_bettinghistory_sub.php:
<?php
error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');
?>
<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<?PHP
//Session start
#session_start();
//Path to root
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
//Require Init
$mode = array();
$mode[] = 'nohtml';
require_once $root . "/inc/php/init.php";
{
?>
<?PHP
}
?>
<?
$qry = "
SELECT timelive,bidprice,match_title,selection,winnings_with_startamount,odds,odds*10 AS gainedodds,username,
CASE
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status LIKE 'E' THEN 'pending'
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status NOT LIKE 'E' THEN 'active'
WHEN each_bid_recorded_Part2.result liKE each_bid_recorded_Part2.selection THEN 'WON'
WHEN each_bid_recorded_Part2.result NOT liKE each_bid_recorded_Part2.selection THEN 'LOST'
END AS result
FROM each_bid_recorded_Part2 WHERE each_bid_recorded_Part2.username LIKE '" . $_SESSION['username'] . "'
";
$qry .= " ORDER BY timelive DESC";
//for pagination
if(isset($_GET['starting'])&& !isset($_REQUEST['submit'])){
$starting=$_GET['starting'];
}else{
$starting=0;
}
$recpage = 4;//number of records per page
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
function getStyleColorForStatus($status) {
if ($status == 'WON') {
return '#99ff99';
}
else if ($status == 'LOST') {
return '#ff9999';
}
else if ($status == 'pending') {
return '#e5e5e5';
}
return '';
}
?>
<div>
<div class="pageTop"><img src="images/icons/faqicon.png" width="37" height="37" align=absbottom> Betting History</div>
<tr>
<td> </td>
</tr>
</div>
<div>
<p style="font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #535252; text-align: left;">Check your bets with you as a last bidder.</p>
</div>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-size:11px; color: #535252;">
</div>
</div>
<table border="0" align="left" width="500px" padding-left="0px" style="background:#F9F9F9;">
<tr><TD colspan="0">
<div id="page_contents">
<table width="98%" cellspacing="0" cellpadding="5" align="center" frame="box" rules="none" style="padding-bottom:2px; margin-bottom:0px; margin-top:3px; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1); border: 1px solid #cccccc;">
<tr style="height: 40px;">
<td width="30%" align="center" td class="winheader"><div class="glowtext">Event Start Time</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Bid Cost</div></td></td>
<td width="35%" align="center" td class="winheader"><div class="glowtext">Market/Event</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Selection</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winnings</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Odds</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Gained Odds</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winning Bidder</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Final Result</div></td></td>
</tr>
<?if(mysql_num_rows($result)!=0){
$counter = $starting + 1;
while($data = mysql_fetch_array($result)) {?>
<tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
<td align="center"><font color="#333"><? echo $data['timelive']; ?></TD>
<td align="center">€ <? echo $data['bidprice']; ?></TD>
<td align="left"><font color="#0070c0"><? echo $data['match_title']; ?></TD>
<td align="left"><? echo $data['selection']; ?></TD>
<td align="center"><font color="green">€ <? echo $data['winnings_with_startamount']; ?></TD>
<td align="center"><? echo $data['odds']; ?></TD>
<td align="center"><? echo $data['gainedodds']; ?></TD>
<td align="center"><? echo $data['username']; ?></TD>
<td align="center" style="background-color:<?php echo getStyleColorForStatus($data['result']); ?>"><? echo $data['result']; ?></td>
</tr>
<?
$counter ++;
} ?>
<tr><TD align="center" colspan="10" style="padding-bottom:1px; padding-top:10px; color:#333;"><? echo $obj->anchors; ?></TD></tr>
<tr><TD align="center" colspan="10" style="padding-bottom:10px; padding-top:5px; color:#333;"><? echo $obj->total; ?></TD></tr>
<?}else{?>
<tr><TD align="center" colspan="10" style="padding-bottom:10px padding-top:10px; color:red;">No Data Found</TD></tr>
<?}?>
</TD></tr>
</table>
</div>
</tr>
</TD>
</table>
pagination.js:
var xmlHttp
function pagination(page)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="myaccount_bettinghistory_sub.php";
url = url+"?starting="+page;
url = url+"&search_text="+document.form1.search_text.value;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("page_contents").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
pagination_class.php:
<?
/*
Developed by Reneesh T.K
reneeshtk#gmail.com
You can use it with out any worries...It is free for you..It will display the out put like:
First | Previous | 3 | 4 | 5 | 6 | 7| 8 | 9 | 10 | Next | Last
Page : 7 Of 10 . Total Records Found: 20
*/
class Pagination_class{
var $result;
var $anchors;
var $total;
function Pagination_class($qry,$starting,$recpage)
{
$rst = mysql_query($qry) or die(mysql_error());
$numrows = mysql_num_rows($rst);
$qry .= " limit $starting, $recpage";
$this->result = mysql_query($qry) or die(mysql_error());
$next = $starting+$recpage;
$var = ((intval($numrows/$recpage))-1)*$recpage;
$page_showing = intval($starting/$recpage)+1;
$total_page = ceil($numrows/$recpage);
if($numrows % $recpage != 0){
$last = ((intval($numrows/$recpage)))*$recpage;
}else{
$last = ((intval($numrows/$recpage))-1)*$recpage;
}
$previous = $starting-$recpage;
$anc = "<ul id='pagination-flickr'>";
if($previous < 0){
$anc .= "<li class='previous-off'><<</li>";
$anc .= "<li class='previous-off'><</li>";
}else{
$anc .= "<li class='next'><a href='javascript:pagination(0);'><< </a></li>";
$anc .= "<li class='next'><a href='javascript:pagination($previous);'>< </a></li>";
}
################If you dont want the numbers just comment this block###############
$norepeat = 4;//no of pages showing in the left and right side of the current page in the anchors
$j = 1;
$anch = "";
for($i=$page_showing; $i>1; $i--){
$fpreviousPage = $i-1;
$page = ceil($fpreviousPage*$recpage)-$recpage;
$anch = "<li><a href='javascript:pagination($page);'>$fpreviousPage </a></li>".$anch;
if($j == $norepeat) break;
$j++;
}
$anc .= $anch;
$anc .= "<li class='active'>".$page_showing."</li>";
$j = 1;
for($i=$page_showing; $i<$total_page; $i++){
$fnextPage = $i+1;
$page = ceil($fnextPage*$recpage)-$recpage;
$anc .= "<li><a href='javascript:pagination($page);'>$fnextPage</a></li>";
if($j==$norepeat) break;
$j++;
}
############################################################
if($next >= $numrows){
$anc .= "<li class='previous-off'>></li>";
$anc .= "<li class='previous-off'>>></li>";
}else{
$anc .= "<li class='next'><a href='javascript:pagination($next);'>> </a></li>";
$anc .= "<li class='next'><a href='javascript:pagination($last);'>>></a></li>";
}
$anc .= "</ul>";
$this->anchors = $anc;
$this->total = "Page : $page_showing of $total_page Total Records Found: $numrows";
}
}
?>
remove this
&& !isset($_REQUEST['submit'])
you are not using it !!!

Categories