Colspan breaks table - php

ORIGINAL
I have a page that displays all the company boardrooms and bookings for a certain day. It looks like this:
As you can see, some of the rows create an extra <td>
Here is the code that generates the table:
<table celladding="0" cellspacing="0" class="table table-bordered col-xs-12">
<thead>
<tr style="background-color:#FFF">
<?php
$width = (100 / (count($boardrooms->toArray()) + 1));
$width = 100 / 7;
?>
<th style="border-right:none; width:<?= $width; ?>%; border-bottom: none;">Boardroom</th>
<?php
foreach($boardrooms as $boardroom) { ?>
<th rowspan="2" style="width:<?= $width; ?>%"><?php echo $boardroom ?></th>
<?php } ?>
</tr>
<tr>
<th>Time</th>
</tr>
</thead>
<?php
$writerow = false;
for($hour = 8; $hour < 17; $hour++) {
for($minute = 0; $minute < 4; $minute++) {
echo '<tr><td>' . $hour . ':' . str_pad(($minute*15),2,"0") . '</td>';
foreach($boardrooms as $boardroom) {
foreach($boardroomBookings as $booking) {
if(date('H:i',strtotime($hour . ':' . str_pad(($minute*15),2,"0"))) >= date('H:i',strtotime($booking->start_time)) &&
date('H:i',strtotime($hour . ':' . str_pad(($minute*15),2,"0"))) < date('H:i',strtotime($booking->end_time)) &&
$boardroom == $booking->boardroom->name && (empty($boardroomWritten[$booking->id]) || !$boardroomWritten[$booking->id])) {
$boardroomWritten[$booking->id] = true;
$writerow = true;
$rowspan = (strtotime($booking->end_time) - strtotime($booking->start_time))/900;
echo '<td style="background-color:#8cc63f; border-bottom:none" rowspan="' . $rowspan . '">' . $this->Html->link($booking->name, array('action' => 'view', $booking->id)) . '</td>';
break;
} else {
$writerow = false;
}
}
if(!$writerow) {
echo '<td></td>';
}
}
echo '</tr>';
}
}
?>
</table>
How can I prevent the rows from displaying the extra empty cell on rows that have a booking?
EDIT
Here's the same table with black borders:
And what it looks like without a booking:
And what it should look like with a booking:

If you don't have a booking you need to insert a td pair unless you are inside a colspan:
<?php
for($hour = 8; $hour < 17; $hour++) {
for($minute = 0; $minute < 4; $minute++) {
$bookTime = date('H:i ',strtotime($hour . ':' . str_pad(($minute*15),2,"0"))) ;
echo '<tr><td>' . $bookTime . '</td>';
foreach($boardrooms as $boardroom) {
$hasBooking = false;
foreach($boardroomBookings as $booking) {
$sTime = strtotime($booking->start_time) ;
$eTime = strtotime($booking->end_time) ;
$startTime = date('H:i',$sTime);
$endTime = date('H:i', $eTime) ;
if($bookTime >= $startTime && $bookTime < $endTime && $boardroom == $booking->boardroom->name) {
$hasBooking = true;
if(empty($boardroomWritten[$booking->id]) || !$boardroomWritten[$booking->id]) {
$boardroomWritten[$booking->id] = true;
$rowspan = ($eTime - $sTime)/900 ;
echo '<td style="background-color:#8cc63f; border:1px black solid" rowspan="' . $rowspan . '">' . "somelink" . '</td>';
break;
}
}
}
if (!$hasBooking) {
echo "<td></td>" ;
}
}
echo '</tr>';
}
}

Related

PHP Loop Month Row, with Weekly columns

I'm setting up a report with the following columns, Month, Teller, Week 1, Week 2, week 3, Week 4, and Week 5 and a Total collection of the Month.
I have difficulties to sum up the amount from the database for each week of a row.
Maybe if anyone can help me how to show the list of dates within each week of a month, could be helpfull!
That will show a monthly weekly collection of tellers.
I wan't to sum the collection from the database weekly from the month every tellers.
Database Table
My Code.
if($teller_cnt > 0) {
$new_start_week = 0;
$weeks_num = 5;
for($m = 1; $m<=12; $m++) {
$weeks_num = weeks_num($m, $year);
$num_of_weeks = $weeks_num;
$monthname = date_formating($m, '!m', 'F');
$total_per_month = 0;
$min_1 = 0;
if($m > 1) {
if($num_of_weeks == 4) {
$new_start_week = ($new_start_week + $weeks_num) + 1;
$weeks_num = ($weeks_num + $new_start_week);
$msg = '<span class="label label-danger">4 Months</span>';
}else{
$new_start_week = ($new_start_week + $weeks_num);
$weeks_num = ($weeks_num + $new_start_week);
$msg = '<span class="label label-info">5 Montsh</span>';
$min_1 = -1;
}
}else{
if($num_of_weeks == 4) {
$msg = '<span class="label label-danger">4 Months</span>';
}else{
$msg = '<span class="label label-info">5 Montsh</span>';
}
}
if(weeks_num(($m-1), $year)==4) {
$weeks_num = $weeks_num - 1;
$new_start_week = $new_start_week - 1;
}
echo '<tr>';
echo '<td rowspan="'.($teller_cnt+1).'">';
echo $monthname.' <br>';
//echo 'Num of Weeks per month: '.$num_of_weeks. ' <br> ';
//echo 'Start Of Week Num: ' . $new_start_week;
//echo $msg . '<br>';
echo '</td>';
echo '</tr>';
foreach ($qry_pay_tellers->result() as $row) {
$qry_total_payapplied = $this->db->query("SELECT SUM(amt) + SUM(intrst) AS amt FROM payapplied WHERE teller = {$row->teller} AND YEAR(tdate) = $year AND MONTH(tdate) = $m")->row();
$total_teller_amt = ($qry_total_payapplied) ? $qry_total_payapplied->amt : 0;
echo '<tr>';
echo '<td>' . $row->teller . '</td>';
/*
$firstDayOfMonth = new \DateTime("1st $monthname");
$lastDayOfMonth = new \DateTime($firstDayOfMonth->format('t M Y'));
$oneDay = new DateInterval('P1D');
$period = new \DatePeriod($firstDayOfMonth, $oneDay, $lastDayOfMonth->add($oneDay));
*/
$days_arr = array();
$begin = new DateTime('2019-01-01');
$end = new DateTime('2019-12-31');
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
foreach($period as $date)
{
$dates = $date->format('Y-m-d');
$week_num = $this->db->query("SELECT WEEK('$dates', 'Monday') AS weeknum;")->row();
$days_arr[$week_num->weeknum][] = array('dayname' => $date->format('D'), 'date' => $dates);
// echo $dates . ' - ' . $week_num->weeknum . '<br>';
}
for($w = $new_start_week; $w < $weeks_num; $w++) {
echo '<td>';
/*
echo $w . '<br>';
foreach($days_arr[$w] as $wrow) {
echo $wrow['date'] . '<br>';
}
*/
echo '</td>';
}
//echo '<td class="number">'.number_format($total_teller_amt, 2).'</td>';
if($num_of_weeks > 4) {
echo '<td class="number">'.number_format($total_teller_amt, 2).'</td>';
}else{
echo '<td colspan="2" class="number">'.number_format($total_teller_amt, 2).'</td>';
}
echo '</tr>';
$total_per_month += $total_teller_amt;
}
echo '<tr>';
echo '<td class="number" colspan="8">'.number_format($total_per_month, 2).'</td>';
echo '</tr>';
}
}
My Solution.
Thanks anyway.
Created Array of Days from Jan to December and identify its week numbers.
$begin = new DateTime( '2019-01-01' );
$end = new DateTime( '2019-12-31' );
$end = $end->modify( '+1 day' );
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
$dates_arr = array();
foreach($daterange as $date){
$dates = $date->format('Y-m-d');
$week_num = $this->db->query("SELECT WEEK('$dates', 'Monday') AS weeknum;")->row();
$month_n = (int)$date->format('m');
$dates_arr[$month_n][] = array(
'week' => $week_num->weeknum,
'dayname' => $date->format('D'),
'dates' => $date->format('Y-m-d')
);
}
Then Create a table to index month and week and query loop tellers
echo '<div class="row">';
echo '<div class="col-md-12">';
echo '<table class="table table-hover table-condensed table-bordered table-striped table-small">';
echo '<thead>';
echo '<th>Month</th>';
echo '<th>Teller</th>';
echo '<th>Week 1</th>';
echo '<th>Week 2</th>';
echo '<th>Week 3</th>';
echo '<th>Week 4</th>';
echo '<th>Week 5</th>';
echo '<th></th>';
echo '<th>Total</th>';
echo '</thead>';
echo '<tbody>';
for($month = 1; $month<=12; $month++) {
$total_per_month = 0;
$weeks_r = array();
foreach ($dates_arr[$month] as $rw) {
$weeks_r[] = $rw['week'];
}
$u_week_r = array_unique($weeks_r);
$monthname = date_formating($month, '!m', 'F');
echo '<tr>';
echo '<td rowspan="' . ($teller_cnt + 1) . '">';
echo $monthname . ' <br>';
echo '</td>';
echo '</tr>';
$total_teller_amt = 0;
foreach ($qry_pay_tellers->result() as $row) {
echo '<tr>';
echo '<td>' . $row->teller . '</td>';
foreach ($u_week_r as $wrow) {
echo '<td class="number" style="font-size: 8px;">';
$dates_arr_s = array();
foreach ($dates_arr[$month] as $drow) {
if ($drow['week'] == $wrow) {
if(isWeekend($drow['dates']) == false) {
$dates_arr_s[] = $drow['dates'];
$qry_pay_applied_wamt = $this->db->query("
SELECT SUM(amt) + SUM(intrst) AS amt FROM payapplied WHERE teller = {$row->teller} AND CAST(tdate AS DATE) = '{$drow['dates']}'
")
->row();
$amt_per_week = ($qry_pay_applied_wamt) ? $qry_pay_applied_wamt->amt : 0;
$total_teller_amt += $amt_per_week;
echo '<span style="float: left !important;">'.$drow['dates'] . ' - ' . $drow['dayname'] . '</span><span class="pull-right">'.number_format($amt_per_week, 2).'</span><br>';
}
}
}
echo '</td>';
}
if(count($u_week_r) > 4) {
if(count($u_week_r) > 5) {
echo '<td class="number">' . number_format($total_teller_amt, 2) . '</td>';
}else{
echo '<td colspan="2" class="number">' . number_format($total_teller_amt, 2) . '</td>';
}
} else {
echo '<td colspan="3" class="number">' . number_format($total_teller_amt, 2) . '</td>';
}
echo '</tr>';
$total_per_month += $total_teller_amt;
}
echo '<tr>';
echo '<td class="number" colspan="9">'.number_format($total_per_month, 2).'</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
echo '</div>';
echo '</div>';

PHP: Set table cell background based on result

I'm trying to generate colours based on output of a csv (originally formatted ping).
I can get the values no problem,but the if, ifelse, else doesn't seem to be working.
if($min > 0.499 && $min <= 1) {$tcolor = $yellow;} elseif($min >= 1.0) {$tcolor = $red; } else { $tcolor = $white;}
if($avg > 0.499 && $avg <= 1) {$tcolor = $yellow;} elseif($avg >= 1.0) {$tcolor = $red; } else { $tcolor = $white;}
if($max > 0.499 && $max <= 1) {$tcolor = $yellow;} elseif($max >= 1.0) {$tcolor = $red; } else { $tcolor = $white;}
if($mdev > 0.499 && $mdev <= 1) {$tcolor = $yellow;} elseif($mdev >= 1) {$tcolor = $red; } else { $tcolor = $white;}
echo "<tr><td>$ip</td><td bgcolor=\"$tcolor\">$min<br>$tcolor</td><td bgcolor=\"$tcolor\">$avg<br>$tcolor</td><td bgcolor=\"$tcolor\">$max<br>$tcolor</td><td bgcolor=\"$tcolor\">$mdev</td></tr>";
Edit: As many asked about the colour code already, I have it above the code listed as
$yellow = "#FFFF66";
$red = "#FF0000";
$white = "#FFFFFF";
And the number I see the overlap, but I've also tried with 0.999 with the same result.
It sounds like you got it solved, but you should look at using functions like so, so you don't have to repeat if statements like you did.
<?php
function setCellColor($value){
$color = '#FFFFFF';
if($value >= 0.5 && $value <= 1){
$color = '#FFFF00';
} else if($value > 1) {
$color = '#FF0000';
}
return ' style="background: ' . $color . '" ';
}
echo '<tr><td>' . $ip . '</td><td ' . setCellColor($min) . '>' . $min . '</td><td ' . setCellColor($avg) . '>' . $avg . '</td><td ' . setCellColor($max) . '>' . $max . '</td><td ' . setCellColor($mdev) . '>' . $mdev . '</td></tr>';
?>
Check this out:
function build_td_with_style($value) {
switch (true) {
case $value > 0.5 && $value <= 1 :
$class = 'yellow';
break;
case $value > 1 :
$class = 'red';
break;
default :
$class = 'white';
}
return "<td class='{$class}'>{$value}</td>";
}
$tds = implode('', array_map("build_td_with_style", [$min, $avg, $max, $mdev]));
echo "<tr><td>{$ip}</td>{$tds}</tr>";
style.css :
.yellow {
background-color: yellow;
}
.red {
background-color: red;
}
.white {
background-color: white;
}

PHP Leaderboard add (t) for ties

I have a php leaderboard and it works great, and works well with ties. Currently it will number users from 1st to last place (whichever # that is), and if there are ties, it lists them all out with the same number.
For example:
userC 2. userG 3. userA 3. userT 3. userJ 4. userW 5. userP
What I would like is for when there are ties, for the leaderboard to display a "(t)" next to the number, like so: (t) 3. userT
Here is my code, any help is appreciated:
<table cellpadding="4" cellspacing="0" class="table1" width="100%"><caption>
<h2>Leaderboard</h2>
</caption>
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$i = 1;
$tmpScore = 0;
//show place #
foreach($playerTotals as $playerID => $stats) {
if ($tmpScore < $stats[score]) $tmpScore = $stats[score];
//if next lowest score is reached, increase counter
if ($stats[score] < $tmpScore ) $i++;
$pickRatio = $stats[score] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
//display users/stats
$rowclass = ((($i - 1) % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . $i . '</b>. ' . $stats[userName] . '</td><td align="center">' . $stats[wins] . '</td><td align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
$tmpScore = $stats[score];
}
}
echo ' </div>' . "\n";
?>
</table>
Try this code... hope it will resolve your issue
<table cellpadding="4" cellspacing="0" class="table1" width="100%">
<caption><h2>Leaderboard</h2></caption>
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$j = 1;
$tmpScore = 0;
//show place #
$tieflag=false;
for($i=0; $i<=count($playerTotals)-1; $i++) {
if(($i<count($playerTotals) && $playerTotals[$i][score]==$playerTotals[$i+1][score]) || ($i>0 && $playerTotals[$i][score]==$playerTotals[$i-1][score])) $tieflag=true;
$pickRatio = $$playerTotals[$i][score] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($playerTotals[$i][score] / $possibleScoreTotal) * 100), 2) . '%';
$rowclass = ((($j - 1) % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . ($tieflag?'(t)'.$j:$j) . '</b>. ' . $playerTotals[$i][userName] . '</td><td align="center">' . $playerTotals[$i][wins] . '</td><td align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
$j++;
}
}
echo '</div>'. "\n";
?>
</table>
I'd create a new variable $placeholder. So:
if ( $i != 0 ) {
if ($tmpScore < $stats[score]) {
$tmpScore = $stats[score];
}
if ( $tmpScore == $stats[score] ) {
$placeholder = $i.'(t)';
} else if ($stats[score] < $tmpScore )
$placeholder = $++i;
}
} else {
$placeholder = $++i;
$firstScore = $stats[score];
$tmpScore = $stats[score];
}
Then instead of printing $i print $placeholder
so for the first time through you could do this in the echo:
//It makes more sense if you read it from bottom to top but I put it this way
//so you will not have to keep running through every condition when you will
//only evaluate the first condition most often
if ( $i != 0 && $i != 1 ) {
echo ;//Your normal print
} else if ( $i = 1 && $tmpScore != $firstScore ) {
echo '<b>'; //and the rest of the first line plus second line NOT a tie
} else if ( $i = 1 ) {
echo ' (t)'; //Plus the rest of your first line plus second line TIE
} else {
//This is your first time through the loop and you don't know if it's a tie yet so just
//Print placeholder and then wait to figure out the rest
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . $placeholder;
}

Drop down menu filter for SELECT COUNT results php

I have a script which retrieves all rows of data within a sales list (npc_sales_list) but what I am trying to do is set up a drop down menu which filters the results oand I don't know where to start as I haven't done any php in while.
The main filters I am trying to do are to see the previous month's sales only (npc_entry_date) and the sales type (npc_usertype). If someone could point me in the right direction or show me some resource links that would be great.
Im not fussed whether the filter is automatic or if you need to hit a submit button. Any suggestions welcome...
<?php
require_once ('./includes/config.inc.php');
$page_title = 'Page title';
include ('./includes/header.html');
if (!isset($_SESSION['admin_sp_id'])) {
$url = 'http://' . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1);
}
$url .= '/login.php';
ob_end_clean();
header("Location: $url");
exit();
}
require_once ('database.php');
$display = 500;
if (isset($_GET['np'])) {
$num_pages = $_GET['np'];
} else {
$query = "SELECT COUNT(*) FROM npc_sales_list ORDER BY npc_entry_date DESC";
$result = #mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
if ($num_records > $display) {
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$link1 = "{$_SERVER['PHP_SELF']}?sort=fna";
$link2 = "{$_SERVER['PHP_SELF']}?sort=lna";
if (isset($_GET['sort'])) {
switch ($_GET['sort']) {
case 'fna':
$order_by = 'sp_firstname ASC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=fnd";
break;
case 'fnd':
$order_by = 'sp_firstname DESC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=fna";
break;
case 'lna':
$order_by = 'sp_surname ASC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=lnd";
break;
case 'lnd':
$order_by = 'sp_surname DESC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=lna";
break;
default:
$order_by = 'npc_entry_date DESC';
break;
}
// $sort will be appended to the pagination links.
$sort = $_GET['sort'];
} else { // Use the default sorting order.
$order_by = 'npc_entry_date DESC';
$sort = 'drd';
}
$query = "SELECT us.sp_firstname , us.sp_surname , us.sp_amb_club_no , us.sp_position_title , us.sp_dealer_name ,
us.sp_dealer_code , us.sp_region , us.sp_department, sp_business_phone, us.sp_mobile_phone , us.sp_dealer_category, us.sp_email,
sa.npc_item_id , sa.npc_part_no, sa.npc_quantity, sa.npc_customer_name, sa.npc_registration_no , sa.npc_suo_no , sa.npc_amb_club_no , sa.npc_repair_order , sa.npc_invoice_no ,
sa.npc_entry_userdate, sa.npc_image_upload, sa.npc_usertype, sa.npc_points, sa.npc_bonus_points, sa.npc_active, sa.npc_entry_date,
DATE_FORMAT(sa.npc_entry_date, '%d-%m-%Y') AS dr , sa.sp_user_id
FROM sp_user AS us, npc_sales_list AS sa
WHERE us.sp_user_id = sa.sp_user_id
ORDER BY
$order_by LIMIT $start, $display";
$result = #mysql_query ($query);
//
// Table header.
echo '<table width="100%" cellspacing="1" cellpadding="4" style="font-size:10px;">
<tr>
<td align="center"><b>Invoice No.</b></td>
<td align="center"><b>Member ID</b></td>
<td align="center"><b>Surname</b></td>
<td align="center"><b>Part #</b></td>
<td align="center"><b>Sale Type</b></td>
<td align="center"><b>Qty</b></td>
<td align="center"><b>Invoice Date</b></td>
<td align="center"><b>Customer Rego</b></td>
<td align="center"><b>Submission Date</b></td>
<td align="center"><b>Status</b></td>
</tr>';
// Fetch and print all the records. echo '<td align="left"><strong>' . $row['sp_invoice_no'] . '</strong></td> ';
$bg = '#ffffff'; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bg = ($bg=='#eaeced' ? '#ffffff' : '#eaeced');
echo '<tr bgcolor="' . $bg . '">';
echo '<td align="center"><strong>Details</strong></td> ';
echo '<td align="center"><strong>' . $row['sp_amb_club_no'] . '</strong></td> ';
echo '<td align="center"><strong>' . $row['sp_surname'] . '</strong></td> ';
echo '<td align="center"> <strong>' . $row['npc_part_no'] . '<strong></td>';
echo '<td align="center"> ' . $row['npc_usertype'] . ' </td>';
echo '<td align="center"> ' . $row['npc_quantity'] . ' </td>';
echo '<td align="center"> ' . $row['npc_entry_userdate'] . ' </td>';
echo '<td align="center"> ' . $row['npc_registration_no'] . ' </td>';
echo '<td align="center"> ' . $row['dr'] . ' </td>';
echo '<td align="center" style="color:#5a8e22; font-weight:bold;"> ' . $row['npc_active'] . ' </td>';
echo '</tr>
';
}
echo '</table>';
mysql_free_result ($result);
mysql_close();
if ($num_pages > 1) {
echo '<br /><p>';
$current_page = ($start/$display) + 1;
if ($current_page != 1) {
echo '<a href="view-all-sales.php?s=' . ($start - $display) . '&np=' .
$num_pages . '&sort=' . $sort .'">Previous</a> ';
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="view-all-sales.php?s=' . (($display * ($i - 1))) .
'&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
} else {
echo $i . ' ';
}
}
if ($current_page != $num_pages) {
echo '<a href="view-all-sales.php?s=' . ($start + $display) . '&np=' .
$num_pages . '&sort=' . $sort .'">Next</a> ';
}
echo '</p>';
}
include ('./includes/footer_admin_user.html');
?>

Could somebody help me to make pagination? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
edited>>
Your posts don't help me at all
I made this
function lgsl_query_css_all($request)
{
global $lgsl_config;
lgsl_database();
$eiluciu_psl = 2;
$psl_num = 1;
if (isset($_GET['puslapis']))
{
$psl_num = $_GET['puslapis'];
}
$offset = ($psl_num-1)* $eiluciu_psl;
$mysql_query = "SELECT `type`,`ip`,`c_port`,`q_port`,`s_port` FROM `{$lgsl_config['db']['prefix']}{$lgsl_config['db']['table']}` WHERE `disabled`=0 ORDER BY `cache_time` ASC LIMIT $offset,$eiluciu_psl";
$mysql_result = mysql_query($mysql_query) or die(mysql_error());
$server_list = array();
while ($mysql_row = mysql_fetch_array($mysql_result, MYSQL_ASSOC))
{
if (strpos($request, "c") === FALSE && lgsl_timer("check")) { $request .= "c"; }
$server = lgsl_query_cached($mysql_row['type'], $mysql_row['ip'], $mysql_row['c_port'], $mysql_row['q_port'], $mysql_row['s_port'], $request);
if ($lgsl_config['hide_offline'][0] && !$server['b']['status']) { continue; }
$server_list[] = $server;
}
$query_count = "SELECT COUNT(id) AS numrows FROM lgsl";
$result_count = mysql_query($query_count) or die (mysql_error());
$row = mysql_fetch_array($result_count,MYSQL_ASSOC);
$numrows = $row['numrows'];
$max_psl = ceil($numrows/$eiluciu_psl);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($puslapis = 1; $puslapis <= $max_psl; $puslapis++)
{
if ($puslapis == $psl_num)
{
$nav .= " $puslapis ";
}
else
{
$nav .= " $puslapis ";
}
}
if ($psl_num > 1)
{
$puslapis = $psl_num - 1;
$prev = " « << ";
$first = " 1 ";
}
else
{
$prev = ' ';
$first = ' ';
}
if ($psl_num < $max_psl)
{
$puslapis = $psl_num + 1;
$next = " >> ";
$last = " $max_psl ";
}
else
{
$next = ' ';
$last = ' ';
}
// 1-4
$vienas = $psl_num + 1;
if($vienas < $max_psl)
{
$vienas_echo = "$vienas";
} else {
$vienas_echo = " ";
}
$du = $psl_num + 2;
if($du < $max_psl)
{
$du_echo = "$du";
} else {
$du_echo = " ";
}
$trys = $psl_num + 3;
if($trys < $max_psl)
{
$trys_echo = "$trys";
} else {
$trys_echo = " ";
}
$keturi = $psl_num + 4;
if($keturi < $max_psl)
{
$keturi_echo = "$keturi";
} else {
$keturi_echo = " ";
}
// 10-40
$desimt = $psl_num + 10;
if($desimt < $max_psl)
{
$desimt_echo = "$desimt";
} else {
$desimt_echo = " ";
}
$dvim = $psl_num + 20;
if($dvim < $max_psl)
{
$dvim_echo = "$dvim";
} else {
$dvim_echo = " ";
}
$trim = $psl_num + 30;
if($trim < $max_psl)
{
$trim_echo = "$trim";
} else {
$trim_echo = " ";
}
$kiam = $psl_num + 40;
if($kiam < $max_psl)
{
$kiam_echo = "$kiam";
} else {
$kiam_echo = " ";
}
$be = $puslapis -1;
$dabar = "" . $be . "";
echo "<div class=\"pagination\" align=\"center\"><ul><li>" . $prev .
"</li><li>" . $first . "</li><li>$dabar</li><li> </li><li>" . $vienas_echo . "</li><li>" . $du_echo .
"</li><li>" . $trys_echo . "</li><li>" . $keturi_echo . "</li><li> <strong>...</strong> </li><li>" . $desimt_echo .
"</li><li>" . $dvim_echo . "</li><li>" . $trim_echo .
"</li><li>" . $kiam_echo . "</li><li>" . $last . "</li><li>" . $next . "</li></ul></div>";
return $server_list;
}
$output .= "
<div style='text-align:center; font-size:10px; font-face:arial'>
<table id='myTable' cellpadding='3' cellspacing='1' style='margin:auto' class='boxes' >
<thead>
<tr class='lgsl'>
<th class='lgsl' style='width:20px;' title='Server Status'>On/Off</th>
<th class='lgsl' style='width:25px;' title='Game'>Gra</th>
<th class='lgsl' style='width:150px;' title='IP address and Port'>IP Serwera</th>
<th class='lgsl' style='width:200px;' title='Server Name'>Nazwa Serwera</th>
<th class='lgsl' style='width:85px;' title='Current Map'>Mapa</th>
<th class='lgsl' style='width:60px;' title='Players online'>Graczy</th>
<th class='lgsl' style='width:100px;' title='User Rating'>Szczegoly</th>
</tr>
</thead>";
foreach ($server_list as $server)
{
$misc = lgsl_server_misc($server);
$server = lgsl_server_html($server);
$output .= "
<tr style='".lgsl_bg().";table-layout:fixed'>
<td>
<img alt='' src='{$misc['icon_status']}' title='{$misc['text_status']}' />
</td>
<td>
<img alt='' src='{$misc['icon_game']}' title='{$misc['text_type_game']}' />
</td>
<td title='{$lgsl_config['text']['slk']}' style='text-align:center'>
<a href='steam://{$misc['software_link']}' class='Tips1' title=' Connect {$server['b']['ip']}:{$server['b']['c_port']}'>
{$server['b']['ip']}:{$server['b']['c_port']}
</a>
</td>
<td title='{$server['s']['name']}' style='text-align:center'>
<div style='width:100%; overflow:hidden; height:1.3em'>
{$misc['name_filtered']}
</div>
</td>
<td style='white-space:nowrap; text-align:center'>
{$server['s']['map']}
</td>
<td style='white-space:nowrap; text-align:center'>
{$server['s']['players']} / {$server['s']['playersmax']}
</td>
<td style='white-space:nowrap; text-align:center'>
<a href='".lgsl_link($server['o']['id'])."'>
<img alt='' src='{$misc['icon_details']}' style='border:none' title='{$lgsl_config['text']['vsd']}' />
</a>
</td>
</tr>";
}
$output .= "
</table>
</div>";
But it looks ugly so i thought someone has better solution
http://img851.imageshack.us/img851/820/unledoxy.png
and i need somehow to place it under the server list
The simplest way to make pagination is to COUNT the total number of rows, and then add a LIMIT to it.
Count the rows:
SELECT COUNT(*) WHERE `disabled`=0 ORDER BY `cache_time` ASC;
Then add your limit:
SELECT `type`,`ip`,`c_port`,`q_port`,`s_port` FROM `{$lgsl_config['db']['prefix']}{$lgsl_config['db']['table']}` WHERE `disabled`=0 ORDER BY `cache_time` ASC LIMIT $start, $perpage;
Where $perpage=20; or any number you would like and $start=(int)$_GET['page']*$perpage;
Simply add links at the bottom for each of the pages you would like to display:
for($a=0;$a<$rows;$a++){
echo"<a href='table.php?page=$a'>$a</a>";
}
That is the gist of it anyways to get you started.
To paginate the mysql query, add a limit clause
LIMIT $begin, $end
Where:
$begin = ($page_num-1)*$NUM_PER_PAGE;
$end = $begin + $NUM_PER_PAGE;

Categories