<?php
$host = "localhost";
$usr = "root";
$pwd = "";
$db= "DB";
conOpen($host,$usr,$pwd,$db);
function conOpen($host,$usr,$pwd,$db){
$con=mysql_connect($host,$usr,$pwd) or die ("Connection Failed ");
mysql_select_db($db,$con);}
$rows_per_page=5;
// database connection stuff here
$result=mysql_query("Select * from newsimage");
$pages=ceil(mysql_num_rows($result)/$rows_per_page);
if (!isset($screen))
  $screen = 0; else echo $_GET[screen];
/*
$start = $screen * $rows_per_page;
$sql = "SELECT nId FROM newsimage ";
$sql .= "LIMIT $start, $rows_per_page";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
for ($i = 0; $i < $rows; $i++) {
  $description = mysql_fetch_array($result);
  echo "\$description = $description[nId]<br>\n";
}
echo "<p><hr></p>\n";
// let's create the dynamic links now
if ($screen > 0) {
  $url = "z.php?screen=" . $screen - 1;
  echo "<a href=\"$url\">Previous</a>\n";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
  $url = "z.php?screen=" . $i;
  echo " | <a href=\"$url\"  onClick=\"window.location.reload(true)\">$i</a> | ";
}
if ($screen < $pages) {
  $url = "z.php?screen=" . $screen + 1;
  echo "<a href=\"$url\">Next</a>\n";
}*/
?>

I am using the above code for record navigation
But On Click on hyperlinks 1,2
I didn't get the next records

Please help me

You should set the $screen variable from $_GET['screen'] instead of echoing it.

i used echo to check only that wheather $_GET[screen] has value or not
But it doesn't have

I agree with pritaeas

if (!isset($_GET[screen]))
  $screen = 0; 
else 
  $screen=$_GET[screen];

But $_GET[screen] is not getting the value...

Please check

Show the HTML of the generated pagination links.

$_GET[screen] should be $_GET["screen"] and will not have a value unless the URL of the page is appended with ?screen=value where "value" is the value.

<?php
$host = "localhost";
$usr = "root";
$pwd = "";
$db= "Dbase";
conOpen($host,$usr,$pwd,$db);
function conOpen($host,$usr,$pwd,$db){
$con=mysql_connect($host,$usr,$pwd) or die ("Connection Failed ");
mysql_select_db($db,$con);}
$rows_per_page=5;


$result=mysql_query("Select * from newsimage");
$pages=ceil(mysql_num_rows($result)/$rows_per_page);
if (!isset($screen))
  $screen = 0; else $screen=$_GET["screen"];

$start = $screen * $rows_per_page;
$sql = "SELECT nId FROM newsimage ";
$sql .= "LIMIT $start, $rows_per_page";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
for ($i = 0; $i < $rows; $i++) {
  $description = mysql_fetch_array($result);
  echo "\$description = $description[nId]<br>\n";
}
echo "<p><hr></p>\n";
// let's create the dynamic links now
if ($screen > 0) {
  $url = "z.php?screen=" . $screen - 1;
  echo "<a href=\"$url\">Previous</a>\n";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
  $url = "z.php?screen=" . $i;
  echo " | <a href=\"$url\"  onClick=\"window.location.reload(true)\">$i</a> | ";
}
if ($screen < $pages) {
  $url = "z.php?screen=" . $screen + 1;
  echo "<a href=\"$url\">Next</a>\n";
}
?>

The above code gives the result

$description = 1
$description = 2
$description = 3
$description = 4
$description = 5

| 0 | | 1 | | 2 | Next

But record navigation doesn't takes place

| 0 | | 1 | | 2 | Next

Show the generated HTML for this.

Try what happens if you remove the Javascript (onClick).

but i didn't used the script Javascript onclick
$_GET["screen"];
doesn't get any value..
I think page has to be submitted to get value in $_GET
but here is not any form submission..
Thats y $_GET doesn't get the value...

Any solution...?

but here is not any form submission

That's why I suggested to remove the onClick...

...and you still haven't shown me the output HTML.

Assuming the code is still as above, try:

$pageResult = mysql_query($sql);
$rows = mysql_num_rows($pageResult);
for ($i = 0; $i < $rows; $i++) {
    $description = mysql_fetch_array($pageResult);
    echo "\$description = $description[nId]<br>\n";
}

Your problem is with your IF statement on lines 14/15. You're checking the variable $screen before you're putting anything in to it:

if (!isset($screen))
    $screen = 0; else echo $_GET["screen"];

You neede to check it $_GET["screen"] is the one which is set:

if (!isset($_GET["screen"]))
    $screen = 0; else echo $_GET["screen"];

Oh..Thanks a lot Mr. Borzoi..
But i have one more issue left in it
and that is NEXT and PREVIOUS Link..
I want 4nos of link at once..
and on clicking NEXT button, next 4 links i.e (5,6,7,8) should be shown
Can u please help me in this issue..also..
I am very very thankful to you

The way you're passing information into the $url variable wouldn't work. Using the Previous link, your if statement is this:

if ($screen > 0) {
$url = "z.php?screen=" . $screen - 1;
echo "<a href=\"$url\">Previous</a>\n";
}

You'll want to pass the value of $screen - 1 into a different variable which you then pass into $url like this:

if ($screen > 0) {
$previous = $screen - 1;
$url = "z.php?screen=" . $previous;
echo "<a href=\"$url\">Previous</a>\n";
}

You might want a more generic variable name so you can use it with the Next link, which would be the same concept.

Incrementing or decrementing $screen with $screen++/$++screen and $screen--/$--screen wouldn't work as it would cause problems with the Next link.

If that has solved your problem, make sure you mark the thread as solved so that others who may have a similar problem can find the solution easier.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.