Page 1 of 1

please correct this navigation script

Posted: Thu Jul 11, 2002 1:35 am
by harsha
<html>
<head>
<?php

// if a page isn't defined, we're on page one
if($page <= 0)
{
$page = 1;
}

$i=0;

// create an array of data
$myArray = file("data.txt");
$s=sizeof($myarray);
// reverse the order of the data
$myArray = array_reverse($myArray);

// how many lines of data to display
$display = 10;

// where to start depending on what page we're viewing
$start = ($page * $display) - $display;

// the actual news we're going to print
$news = array_slice($myArray, $start, $display);
?>

</head>
<body bgcolor="Gainsboro" text="#000000">
<?php
if ($page=='' or !$page) { $page=1; }


$end=$display*$page;
$start=$end-$display;

if ($start<>'0') {
$new_page=$page-1;
$prev="<a href='view.php?page=$new_page'><---Previous page</a>";
}
else {
$prev="";
}

if ($end<$s) {
$new_page1=$page+1;
$next="<a href='view.php?page=$new_page1'>Next page---></a>";
}
else {
$next="";
}

echo "$prev";
echo "$next";

?>
<p>
<table width="90%" align="center" bgcolor="gainsboro" border="0" cellpadding="0" cellspacing="0">
<?php
// printing the data
foreach($news as $key=>$value)
{
$new=explode("#","$value");
echo "<tr><td width=\"50%\"><b>Name:</b>".$new[1]."</td><td width=\"50%\"><b>E-mail:</b>".$new[2]."</td></tr>";
echo "<tr><td colspan=2 align=justify><b>Message:</b><br>".$new[3]."</td></tr>";
echo "<tr><td><b>Posted on:</b>".$new[0]."</td><td><b>smileys:</b>"."</td></tr>";
echo "<tr><td width=\"50%\" height=\"16\"></td><td width=\"50%\" height=\"16\"></td></tr>";
}
?>
</table>
</body>
</html>

Posted: Thu Jul 11, 2002 2:04 am
by hob_goblin

Code: Select all

<html> 
<head> 
<?php 

// if a page isn't defined, we're on page one 
if(!$page || empty($page)) 
&#123; 
$page = 1; 
&#125; 


// create an array of data 
$myArray = file("data.txt"); 
$s=sizeof($myarray); 
// reverse the order of the data 
$myArray = array_reverse($myArray); 

// how many lines of data to display 
$display = 10; 

// where to start depending on what page we're viewing 
$start = ($page * $display) - $display; 

// the actual news we're going to print 
$news = array_slice($myArray, $start, $display); 
?> 

</head> 
<body bgcolor="Gainsboro" text="#000000"> 
<?php 


if ($start != '0') &#123; 
$new_page=$page-1; 
$prev="<a href='view.php?page=$new_page'><---Previous page</a>"; 
&#125; 
else &#123; 
$prev=""; 
&#125; 

if ($end < $s) &#123; 
$new_page1=$page+1; 
$next="<a href='view.php?page=$new_page1'>Next page---></a>"; 
&#125; 
else &#123; 
$next=""; 
&#125; 

echo "$prev"; 
echo "$next"; 

?> 
<p> 
<table width="90%" align="center" bgcolor="gainsboro" border="0" cellpadding="0" cellspacing="0"> 
<?php 
// printing the data 
foreach($news as $value) 
&#123; 
$new=explode("#","$value"); 
echo "<tr><td width="50%"><b>Name:</b>".$new&#1111;1]."</td><td width="50%"><b>E-mail:</b>".$new&#1111;2]."</td></tr>"; 
echo "<tr><td colspan=2 align=justify><b>Message:</b><br>".$new&#1111;3]."</td></tr>"; 
echo "<tr><td><b>Posted on:</b>".$new&#1111;0]."</td><td><b>smileys:</b>"."</td></tr>"; 
echo "<tr><td width="50%" height="16"></td><td width="50%" height="16"></td></tr>"; 
&#125; 
?> 
</table> 
</body> 
</html>
should work ;)

Posted: Thu Jul 11, 2002 2:14 am
by twigletmac
Have you read this:
http://www.devnetwork.net/forums/viewtopic.php?t=511

Mac

PS. Exactly what is the problem that you're having?

Posted: Thu Jul 11, 2002 2:53 am
by gnu2php
The problem could also be on line 15:

$s=sizeof($myarray);

Should be:

$s=sizeof($myArray); (with capital A on myArray)

Posted: Thu Jul 11, 2002 3:52 am
by hob_goblin
ok, an improvement

Code: Select all

<html> 
<head> 
<?php 

// if a page isn't defined, we're on page one 
if(!isset($HTTP_GET_VARS&#1111;'page'])) 
&#123; 
$page = 1; 
&#125; 


// create an array of data 
$myArray = file("data.txt"); 
$s=sizeof($myArray); 
// reverse the order of the data 
$myArray = array_reverse($myArray); 

// how many lines of data to display 
$display = 10; 

// where to start depending on what page we're viewing 
$start = ($page * $display) - $display; 

// the actual news we're going to print 
$news = array_slice($myArray, $start, $display); 
?> 

</head> 
<body bgcolor="Gainsboro" text="#000000"> 
<?php 


if ($start != '0') &#123; 
$new_page=$page-1; 
$prev="<a href='view.php?page=$new_page'><---Previous page</a>"; 
&#125; 
else &#123; 
$prev=""; 
&#125; 

if ($end < $s) &#123; 
$new_page1=$page+1; 
$next="<a href='view.php?page=$new_page1'>Next page---></a>"; 
&#125; 
else &#123; 
$next=""; 
&#125; 

echo "$prev"; 
echo "$next"; 

?> 
<p> 
<table width="90%" align="center" bgcolor="gainsboro" border="0" cellpadding="0" cellspacing="0"> 
<?php 
// printing the data 
foreach($news as $value) 
&#123; 
$new=explode("#","$value"); 
echo "<tr><td width="50%"><b>Name:</b>".$new&#1111;1]."</td><td width="50%"><b>E-mail:</b>".$new&#1111;2]."</td></tr>"; 
echo "<tr><td colspan=2 align=justify><b>Message:</b><br>".$new&#1111;3]."</td></tr>"; 
echo "<tr><td><b>Posted on:</b>".$new&#1111;0]."</td><td><b>smileys:</b>"."</td></tr>"; 
echo "<tr><td width="50%" height="16"></td><td width="50%" height="16"></td></tr>"; 
&#125; 
?> 
</table> 
</body> 
</html>

the problem was probably some parse errors, and/or the way variables were re-stated and it's general sloppyness

Posted: Thu Jul 11, 2002 4:16 am
by twigletmac
Tiny improvement on hob_goblin's code, replace:

Code: Select all

if(!isset($HTTP_GET_VARS&#1111;'page'])) 
&#123; 
$page = 1; 
&#125;
with

Code: Select all

if (!isset($_GET&#1111;'page']) &#123;
    $page = 1;
&#125; else &#123;
    $page = $_GET&#1111;'page'];
&#125;
Use $_GET['page'] if you have PHP version 4.1 or above and $HTTP_GET_VARS['page'] if you have a version less than 4.1.

You're very lucky, harsha, not everybody gets their code rewritten for them like this, it's very generous of hob_goblin to do this. For future reference (and for anyone else), please tell us exactly what the problem is and give any error messages you might be getting because it makes it easier for us to help. Posting a piece of code and just saying 'fix this' is a bit rude.

Mac

Posted: Thu Jul 11, 2002 10:02 am
by protokol
ignore me.

Posted: Thu Jul 11, 2002 10:13 am
by RandomEngy
Errr.. they ARE case sensitive.... I just did a little test:

Code: Select all

$ham = "yay";

echo $HaM;
produced no results, while

Code: Select all

$ham = "yay";

echo $ham;
did.

Maybe you have a funky version or something?

Posted: Thu Jul 11, 2002 10:18 am
by protokol
i just think that i posted to this forum way too early in the morning .. my brain is not awake, yet my eyes are

Posted: Thu Jul 11, 2002 2:32 pm
by fatalcure
Copy and paste this code, should work good for you :)

Code: Select all

<html>
<head><title></title></head>

<body bgcolor="Gainsboro" text="#000000"> 

<?php
     $perpage = 10;
     if (!$page || !is_numeric($page)) $page=1;
     
     // create an array of data 
     $myArray = file("data.txt"); 
     $total=sizeof($myarray); 

     $numpages = ceil($total / $perpage);

     $prev = $page - 1;
     $next = $page + 1;

     if ($numpages > 1) &#123;
          $pagesvar = "<table width=99%><tr><td align=right>Pages: ($numpages) <b>&#1111; &nbsp;";

          if ($page - 3 > 0) $pagesvar .= "<a href='view.php?page=1'><u><<</u></a> &nbsp;&nbsp;";	
          if ($prev > 0 && $prev <= $numpages) $pagesvar .= "<a href='view.php?page=$prev'><u><</u></a> &nbsp;&nbsp;";

          for ($i=$page-2; $i < $page; $i++) &#123;
               if ($i > 0) $pagesvar .= "<a href='view.php?page=$i'><u>$i</u></a> &nbsp;&nbsp;";
          &#125;

          $pagesvar .= "$page &nbsp;&nbsp;";

          for ($i=$page+1; $i <= $page+2; $i++) &#123;
               if ($i <= $numpages) $pagesvar .= "<a href='view.php?page=$i'><u>$i</u></a> &nbsp;&nbsp;";
          &#125;

          if ($next <= $numpages && $next > 0) $pagesvar .= "<a href='view.php?page=$next'><u>></u></a> &nbsp;&nbsp;";
          if ($page + 3 <= $numpages) $pagesvar .= "<a href='view.php?&page=$numpages'><u>>></u></a> ";

          $pagesvar .= "]</b></td></tr></table>";
     &#125;

// reverse the order of the data 
     $myArray = array_reverse($myArray); 

//set starting position
     $start = ($page - 1) * $perpage;

// the actual news we're going to print 
     $news = array_slice($myArray, $start, $perpage); 

//PRINTING START
     echo "
          <table width='90%' align='center' bgcolor='gainsboro' border='0' cellpadding='0' cellspacing='0'>
            <tr><td align='right' colspan='2'>$pagesvar</td></tr>
     ";

foreach($news as $key=>$value) &#123; 
     $new=explode("#","$value"); 
     echo "<tr><td width='50%'><b>Name:</b>".$new&#1111;1]."</td><td width='50%'><b>E-mail:</b>".$new&#1111;2]."</td></tr>"; 
     echo "<tr><td colspan=2 align=justify><b>Message:</b><br>".$new&#1111;3]."</td></tr>"; 
     echo "<tr><td><b>Posted on:</b>".$new&#1111;0]."</td><td><b>smileys:</b>"."</td></tr>"; 
     echo "<tr><td width='50%' height='16'></td><td width='50%' height='16'></td></tr>"; 
&#125; 

     echo "
               <tr><td align='right' colspan='2'>$pagesvar</td></tr>
          </table>
     ";
?>

</body>
</html>
hope this helps 8)

Posted: Thu Jul 11, 2002 3:20 pm
by hob_goblin
you just had to go out-do me eh? :(

oh well, yeah about $_GET, I always like to use HTTP_GET_VARS when im helping people out.. because i try to make sure my method works no matter what. i know my host hasn't updated to 4.2 yet... so i bet there are others

hi thank you every body

Posted: Fri Jul 12, 2002 12:43 am
by harsha
hello

:) i you people are really gr8 i thanx for your effort in helping me. i am a beginner so i am enjoying lot with you people .

hi i got a doubt

Posted: Fri Jul 12, 2002 1:28 am
by harsha
mr hob_goblin

you haven't assigned any value to $end [/u ]in your script