please correct this navigation script
Moderator: General Moderators
- harsha
- Forum Contributor
- Posts: 103
- Joined: Thu Jul 11, 2002 1:35 am
- Location: Bengaluru (Bangalore) > Karnataka > India
please correct this navigation script
<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>
<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>
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
<html>
<head>
<?php
// if a page isn't defined, we're on page one
if(!$page || empty($page))
{
$page = 1;
}
// 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') {
$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 $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>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Have you read this:
http://www.devnetwork.net/forums/viewtopic.php?t=511
Mac
PS. Exactly what is the problem that you're having?
http://www.devnetwork.net/forums/viewtopic.php?t=511
Mac
PS. Exactly what is the problem that you're having?
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
ok, an improvement
the problem was probably some parse errors, and/or the way variables were re-stated and it's general sloppyness
Code: Select all
<html>
<head>
<?php
// if a page isn't defined, we're on page one
if(!isset($HTTP_GET_VARSї'page']))
{
$page = 1;
}
// 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') {
$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 $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>the problem was probably some parse errors, and/or the way variables were re-stated and it's general sloppyness
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Tiny improvement on hob_goblin's code, replace:
with
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
Code: Select all
if(!isset($HTTP_GET_VARSї'page']))
{
$page = 1;
}Code: Select all
if (!isset($_GETї'page']) {
$page = 1;
} else {
$page = $_GETї'page'];
}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
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
Errr.. they ARE case sensitive.... I just did a little test:
produced no results, while
did.
Maybe you have a funky version or something?
Code: Select all
$ham = "yay";
echo $HaM;Code: Select all
$ham = "yay";
echo $ham;Maybe you have a funky version or something?
Copy and paste this code, should work good for you 
hope this helps 
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) {
$pagesvar = "<table width=99%><tr><td align=right>Pages: ($numpages) <b>ї ";
if ($page - 3 > 0) $pagesvar .= "<a href='view.php?page=1'><u><<</u></a> ";
if ($prev > 0 && $prev <= $numpages) $pagesvar .= "<a href='view.php?page=$prev'><u><</u></a> ";
for ($i=$page-2; $i < $page; $i++) {
if ($i > 0) $pagesvar .= "<a href='view.php?page=$i'><u>$i</u></a> ";
}
$pagesvar .= "$page ";
for ($i=$page+1; $i <= $page+2; $i++) {
if ($i <= $numpages) $pagesvar .= "<a href='view.php?page=$i'><u>$i</u></a> ";
}
if ($next <= $numpages && $next > 0) $pagesvar .= "<a href='view.php?page=$next'><u>></u></a> ";
if ($page + 3 <= $numpages) $pagesvar .= "<a href='view.php?&page=$numpages'><u>>></u></a> ";
$pagesvar .= "]</b></td></tr></table>";
}
// 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) {
$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>";
}
echo "
<tr><td align='right' colspan='2'>$pagesvar</td></tr>
</table>
";
?>
</body>
</html>- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- harsha
- Forum Contributor
- Posts: 103
- Joined: Thu Jul 11, 2002 1:35 am
- Location: Bengaluru (Bangalore) > Karnataka > India
hi thank you every body
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 .
- harsha
- Forum Contributor
- Posts: 103
- Joined: Thu Jul 11, 2002 1:35 am
- Location: Bengaluru (Bangalore) > Karnataka > India
hi i got a doubt
mr hob_goblin
you haven't assigned any value to $end [/u ]in your script
you haven't assigned any value to $end [/u ]in your script