Solved

page numbers problem with displaying numbers

Posted on 2004-03-23
8
221 Views
Last Modified: 2006-11-17
how can i output and start from 1 2 3 etc (at the moment it starts at 0 1 2 3 etc

example code
<?php

if($page <= 0)
{
    $page = 1;
}

$myarray = file ($_FILES['keywordfile']['tmp_name']);       // this reads a text file from a php form
$lines = count($myarray);                                               // counts the number of lines for the text file
$fp2 = explode($lines,$myarray);                                    // seperate $myarray to lines

$start = ($page * $lines) - $lines;                                   // how many page numbers will be created

$news = array_splice($myarray, $start, $lines);               // prblem here outputs href numbers that starts with 0 (array_splice problem maybe)
$news=str_replace(" ","-",$news);                                  //replaces all spaces per line with a - on other php page outputs with .php extension

foreach($news as $key=>$value)
{
    echo "<a href=\"$value.html\" title=\"$value\">$key\n</a> | ";    // outputs href links and assigns each text file line per number - starts at 0
}

?>

0
Comment
Question by:playstat
8 Comments
 

Expert Comment

by:krappleby
ID: 10659338
Try instead of placing an if query, Have you tried just a normal statment to set the page start at 1

ie

$page = "1";
0
 
LVL 4

Expert Comment

by:BrianPap22
ID: 10662527
something like this maybe?

$i = 0;
foreach($news as $key=>$value)
{
if ($i > 0) { echo "<a href=\"$value.html\" title=\"$value\">$key\n</a> | "; }
else { $i++; }
}
0
 
LVL 6

Accepted Solution

by:
jkna_gunn earned 500 total points
ID: 10665423
echo "<a href=\"$value.html\" title=\"$value\">" . ($key + 1) . "\n</a> | ";
0
 

Author Comment

by:playstat
ID: 10690850
hi brian

yes you are correct on the display output of the numbers works well except that the first href link 0 is missing its as if you have chopeed off the 0 what im trying to get is 0 href to start at 1 away of nudging the hrefs up one is there anyway to ignore the output of 0 but assign that to 1  1= 2 2=3 etc

best regards

dc  
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:playstat
ID: 10690881
ALso is there any way to only display ten at a time with a next ten to it I am really puzzled here on how to go about it

thx
0
 
LVL 4

Expert Comment

by:BrianPap22
ID: 10692061
what are your pages named like? Are they 1.html, 2.html, 3.html, etc?

foreach($news as $key=>$value) {
  echo "<a href=\"($value+1).html\" title=\"($value+1)\">$key\n</a> | ";
}

I'm not even sure if I understand what you want your output to look like.  List an example set of inputs and their corresponding outputs, please.
0
 

Author Comment

by:playstat
ID: 10695581
hi brian

Yes they are divided by the amount of lines of text from a text file creating $nindexes  so 100 words (dependng on the amount per page say ten = 10 indexes.

These are then numbered $name-1.php $name-2.php etc

The look of the code should be < prev 1 2 3 4 5 6 7 8 9 10 next > ( next > this should be 11 to 20) 21 to 30 and reaching a limit based on the amount of lines in the text file.

Here is the example code i am using for the index pages. this does work well but some of the pages i have are excesive in the amount some are 650 indexes i need to find away of spliting these up. so its user friendly say maybe 50 per page and a prev 50 and next 50 (its assigning the right landing page and duplicating the output that matches the out put page itself if page 51 to 100 the page links must start at 50 and end at 100 with prev and next matching the correct batch.  

<?php

$limit=150; //get this from row count or page count
$now=$_GET['page'];
if($now=="0")
{
$now=1;
}
$start=$now+1;
$end=$start+$nindexes+1;
if ($end >= $limit)
{
$end=$limit;
}
$back=$start-2;
$next=$start+1;
if($back<0)
{
$back=0;
}
if($back>=1)
{
echo " <a href=\"$name-$start.php?page=$back\">&lt;</a> |";
}
echo" $now |";
for($start;$start<=$end;$start++)
{
echo " <a href=\"$name-$start.php#$name-$start\" title=\"$name-$start\">$start</a> |";
}
if($start<=$limit)
{
echo" .. |";
$tens=ceil(($end/10)+1)*10;
for($i=1;$i<=8;$i++)
{
If($tens<$limit)
{
echo " <a href=\"$name-$start.php?page=$tens\">$tens</a> |";
$tens=$tens+10;
}
}
echo " <a href=\"$name-$start.php?page=$next\">&gt;</a>";
}

?>

here is the example code for the results page (reads a text file and assigns the php pages to each number) each line is a word but i need away for starting at 1 for the output and assigning line one of the text file and so on it also needs a < prev 1 2 3 4 5 6 7 8 9 10 next > (this should be 11 to 20) 21 to 30 and reaching a limit based on the amount of lines in the text file.

Basically i have a text file line by line these list words for my site. so for example hosting for free (next line) hosting for 0 etc etc

using str replace for the gaps with a - so the output now is hosting-for-free.php

<?php

if($page <= 0)
{
    $page = 1;
}

$myarray = file ($_FILES['file']['tmp_name']);       // this reads a text file from a php form
$lines = count($myarray);                                               // counts the number of lines for the text file
$fp2 = explode($lines,$myarray);                                    //

$start = ($page * $lines) - $lines;                                   // how many page numbers will be created

$news = array_slice($myarray, $start, $lines);               // prblem here outputs href numbers that starts with 0 (array_splice problem maybe)
$news=str_replace(" ","-",$news);                                  //replaces all spaces per line with a - on other php page outputs with .php extension

$i = 0;
foreach($news as $key=>$value)
{
if ($i > 0) { echo "<a href=\"$value.php\" title=\"$value\">$key\n</a> | "; }
else
{
 $i++;
}
}
if($start<=$limit)
{
echo" .. |";
$tens=ceil(($end/10)+1)*10;
for($i=1;$i<=8;$i++)
{
If($tens<$limit)
{
echo " <a href=\"untitled.php?page=$tens\">$tens</a> |"; // this section is ??? just trying to assign the next ten file name to it (page 11 text file line 11) then that  
                                                                                       // 11th page outputs (assigned to page 1< Prev 11 12 13 14 15 16 17 18 19 20 next >(assigns to 21st page  and  so forth)

$tens=$tens+10;
}
}
echo " <a href=\"untitled.php?page=$next\">&gt;</a>";
}
?>

if you want to talk on msn messenger directcomsytems@hotmail.com I will explain it better maybe via audio (If this is sussed out i will give as many points as nessessary or the max amount this is urgent and the only part of the system I cant seem to figure out lol its probably a simpe solution I know you can suss out

best Regards

DC
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 10935512
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now