0

I have table named 'user' that has 3 fields 'name' ,'id' and 'profile'. table is filled and 'id' field is filled with 1 to 18 (that is 18 rows).when i run this script it shows the result ::

18
17
16
15
14
Pages4) [1] 2 3 4 >> Last >>

My problem is that when i am clicking on the below any of them link that is(Pages4) [1] 2 3 4 >> Last >> ). It is not going anyhwere,it shows the same page. I want to make this script show after all the ids upto 1.

Please help me make this script work like that.

Thanks in advance

I am pasting the whole script below::

<?php
 
$server = "localhost";
$user = "gallary";
$pass = "flower";
$databasename = "mydbase";
$db = mysql_connect($server, $user, $pass);
mysql_select_db($databasename,$db);
 
$sql = "SELECT id,name FROM user ORDER BY id DESC ";
$query = mysql_query($sql,$db);
$total_results = mysql_num_rows($query);
$limit = "5"; //limit of archived results per page.
$total_pages = ceil($total_results / $limit); //total number of pages
if (empty($page))
{
$page = "1"; //default page if none is selected
}
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB
 
$query = "SELECT id,name FROM user ORDER BY id DESC LIMIT $offset, $limit";
$result = mysql_query($query);
//This is the start of the normal results...
 
while ($row = mysql_fetch_array($result))
{
// display your results as you see fit here.
echo $row['id'];
echo "<br>";
}
mysql_close();
 
 
// This is the Previous/Next Navigation
echo "<font face=Verdana size=1>";
echo "Pages:($total_pages)&nbsp;&nbsp;"; // total pages
if ($page != 1)
{
echo "<a href=$PHP_SELF?page=1><< First</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
$prevpage = $page - 1;
echo "&nbsp;<a href=$PHP_SELF?page=$prevpage><<</a>&nbsp;"; // Previous Page Link
}
if ($page == $total_pages)
{
$to = $total_pages;
}
elseif ($page == $total_pages-1)
{
$to = $page+1;
}
elseif ($page == $total_pages-2)
{
$to = $page+2;
}
else
{
$to = $page+3;
}
if ($page == 1 || $page == 2 || $page == 3)
{
$from = 1;
}
else
{
$from = $page-3;
}
 
for ($i = $from; $i <= $to; $i++)
 
{
if ($i == $total_results) $to=$total_results;
if ($i != $page)
{
echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>";
}
else
{
echo "<b><font face=Verdana size=2>[$i]</font></b>";
}
if ($i != $total_pages)
echo "&nbsp;";
}
if ($page != $total_pages)
{
$nextpage = $page + 1;
echo "&nbsp;<a href=$PHP_SELF?page=$nextpage>>></a>&nbsp;"; // Next Page Link
echo "&nbsp;&nbsp;&nbsp;<a href=$PHP_SELF?page=$total_pages>Last >></a>"; // Last Page Link
}
echo "</font>";
 
// This is the end of the Previous/Next Navigation
?>
3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by vaibhav1983
0

All of the 'href' value needs quote. You have already used double quote for php, so use single quote or use double quote by escaping it.

echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=" . $nextpage . "'>Next</a>";

or

echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $nextpage . "\">Next</a>";

Hope that help.

0

i tried both but still the problem is same..please help . :(

Now the modified code is :

<?php
	// copied from http://www.daniweb.com/forums/thread1720.html
	$server = "localhost";
    $user = "hackrepu";
    $pass = "0hrRa0ibGU";
    $databasename = "hackrepu_prev_next";
    $db = mysql_connect($server, $user, $pass);
    mysql_select_db($databasename,$db);
     
    //$sql = "SELECT id,name FROM user ORDER BY id DESC ";
	$sql = "SELECT * FROM user WHERE id>0 ORDER BY id DESC ";
    $query = mysql_query($sql,$db);
    $total_results = mysql_num_rows($query);
    $limit = "5"; //limit of archived results per page.
    $total_pages = ceil($total_results / $limit); //total number of pages
	echo "First <br>";
	echo $page;
	echo "<br>";
    if (empty($page))
    {
    $page = "1";
	echo "<br>";
	echo $page;
	echo "<br>Default page if none is selected";//default page if none is selected
    }
	
	
    $offset = ($page - 1) * $limit; //starting number for displaying results out of DB
     echo "<br>offset = ";
	 echo $offset;
	 echo "<br>";
    //$query = "SELECT id,name FROM user ORDER BY id DESC LIMIT $offset, $limit";
	$query = "SELECT * FROM user WHERE id>0 ORDER BY id DESC LIMIT $offset, $limit";
    $result = mysql_query($query);
    //This is the start of the normal results...
	
     
    while ($row = mysql_fetch_array($result))
    {
    // display your results as you see fit here.
	echo $row['id'];
	echo "<br>";
	}
    mysql_close();
     
     
    // This is the Previous/Next Navigation
    echo "<font face=Verdana size=1>";
    echo "Pages:(" . $total_pages . ")&nbsp;&nbsp;"; // total pages
    if ($page != 1)
    {
    echo "<a href='" . $PHP_SELF . "?page=1'><< First</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
    $prevpage = $page - 1;
    echo "&nbsp;<a href='" . $PHP_SELF . "?page=" . $prevpage . "'><<</a>&nbsp;"; // Previous Page Link
    }
    if ($page == $total_pages)
    {
    $to = $total_pages;
    }
    elseif ($page == $total_pages-1)
    {
    $to = $page+1;
    }
    elseif ($page == $total_pages-2)
    {
    $to = $page+2;
    }
    else
    {
    $to = $page+3;
    }
    if ($page == 1 || $page == 2 || $page == 3)
    {
    $from = 1;
    }
    else
    {
    $from = $page-3;
    }
     
    for ($i = $from; $i <= $to; $i++)
     
    {
    if ($i == $total_results) $to=$total_results;
    if ($i != $page)
    {
    echo "<a href='" . $PHP_SELF . "?showold=yes&page=" . $i . "'>" . $i . "</a>";
    }
    else
    {
    echo "<b><font face=Verdana size=2>[" . $i . "]</font></b>";
    }
    if ($i != $total_pages)
    echo "&nbsp;";
    }
    if ($page != $total_pages)
    {
    $nextpage = $page + 1;
    //echo "&nbsp;<a href=$PHP_SELF?page=$nextpage>>></a>&nbsp;"; // Next Page Link
	echo "<a href=\"" . $PHP_SELF . "?page=" . $nextpage . "\">Next</a>";
	
	//echo "<a href='" . $PHP_SELF . "?page=" . $nextpage . "'>Next</a>";
    echo "&nbsp;&nbsp;&nbsp;<a href='" . $PHP_SELF . "?page=" . $total_pages . "'>Last >></a>"; // Last Page Link
    }
    echo "</font>";
    echo "last <br>";
	echo $page;
    // This is the end of the Previous/Next Navigation
	?>
0

Try to first store the string you are trying to make in a variable.

E.g.

$output="<a href=\"" . $_SERVER . "?page=" . $nextpage . "\">Next</a>";

Then do an echo of the variable....

This might give u a good idea...

Make a test script and see what is the value.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.