Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

page numbers problem with displaying numbers

Posted on 2004-03-23
8
Medium Priority
?
271 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 1500 total points
ID: 10665423
echo "<a href=\"$value.html\" title=\"$value\">" . ($key + 1) . "\n</a> | ";
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

886 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