Jump to content

search from database(refersh page)..


kar07

Recommended Posts

Hi Friends,

 

i am new to php programming...

 

    in my php application i just retrive record from mysql databse.where i put the condition "SELECT id,yearday ,thisyear,startdate,enddate FROM tblpcspcbdtt

          where startdate >='$sdate' "

 

i pass the date from html page as a post method..

 

afterthat i can dispaly the records in php page..it says 6 pages...when i try to move next page it is change to 82 pages  ....because initially i run without any condition like that. "SELECT id,yearday ,thisyear,startdate,enddate FROM tblpcspcbdtt" .it has 82 pages..

 

but now i already put date condition in the query , after that it says 6 pages..but after i ckick next url it's goes back to 82 pages, then display the 82 pages records.but really i need to see only the 6 pages..

 

i dn't know why it is goes back old pages??..

 

please help me..

 

 

here are my code..

-----------------------------------------------

 

<html>

<head>

<title>Test Result</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

                                        <h1><b> Test Result</b></h1>

</head>

<body bgcolor="Aquamarine">

 

 

<?php

include 'library/config.php';

include 'library/opendb.php';

 

// how many rows to show per page

$rowsPerPage = 10;

 

 

//$CHECKDT=$_POST["name"];

 

// by default we show first page

$pageNum = 1;

//$emp_id =  $_POST["name"];

$sdate =  $_POST["dt1"];

//$edate =  $_POST["dt2"];

//echo($emp_id);

//echo($sdate);

//echo($edate);

 

// if $_GET['page'] defined, use it as page number

if(isset($_GET['page']))

{

$pageNum = $_GET['page'];

 

}

 

// counting the offset

$offset = ($pageNum - 1) * $rowsPerPage;

 

$query  = " SELECT id,yearday ,thisyear,startdate,enddate FROM tblpcspcbdtt

          where startdate >='$sdate' ";

          //and enddate <='$edate'

          //where id = '$emp_id'

 

$pagingQuery = "LIMIT $offset, $rowsPerPage";

$result = mysql_query($query . $pagingQuery) or die('Error, query failed2');

 

// print the student info in table

echo '<table border="1" bgcolor=#FFFFFF" align ="center"><tr><td>Serial Id</td><td>Yearday</td><td>Year</td><td>StartDate</td><td>End Date</td></tr>';

while(list($id, $yearday, $thisyear, $startdate, $enddate) = mysql_fetch_array($result))

{

echo "<tr><td>$id</td><td>$yearday</td><td>$thisyear</td><td>$startdate</td><td>$enddate</td></tr>";

}

echo '</table>';

echo '<br>';

 

 

$result  = mysql_query($query) or die('Error, query failed1');

$numrows = mysql_num_rows($result);

  echo $numrows;

 

$maxPage = ceil($numrows/$rowsPerPage);

 

$self = $_SERVER['PHP_SELF'];

 

 

 

 

 

if ($pageNum > 1)

{

$page = $pageNum - 1;

$prev = "<a href=\"$self?page=$page\">[Prev]</a>";

 

$first = "<a href=\"$self?page=1\">[First Page]</a>";

}

else

{

$prev  = ' [Prev] ';

$first = ' [First Page] ';

}

 

 

if ($pageNum < $maxPage)

{

$page = $pageNum + 1;

$next = "<a href=\"$self?page=$page\">[Next]</a>";

 

$last = "<a href=\"$self?page=$maxPage\">[Last Page]</a>";

}

else

{

$next = ' [Next] ';      // we're on the last page, don't enable 'next' link

$last = ' [Last Page] '; // nor 'last page' link

}

 

 

// print the page navigation link

echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;

 

include 'library/closedb.php';

?>

</body>

</html>

 

--------------------------------------------------

 

 

 

waiting for your valable reply....

 

 

with regards,

kar07..

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.