Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

page numbers problem with displaying numbers

Posted on 2004-03-23
8
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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