page numbers problem with displaying numbers

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
}

?>

playstatAsked:
Who is Participating?
 
jkna_gunnCommented:
echo "<a href=\"$value.html\" title=\"$value\">" . ($key + 1) . "\n</a> | ";
0
 
krapplebyCommented:
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
 
BrianPap22Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
playstatAuthor Commented:
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
 
playstatAuthor Commented:
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
 
BrianPap22Commented:
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
 
playstatAuthor Commented:
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
 
ldbkuttyCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.