This is a program to divide the records in a table between more than one page
depending on from which record onwards you want to display and how many records
per page you want to display. This program was written by Rajendra k. Shrestha My
email address rajensama@yahoo.com You are free to use ,change and distribute the
script to anybody any where and I do not have any responsibility if it does not
work but if you have any problem with script you may contact me in my email address
To use this file
1. create a database with username and password
I have used user "sa77bk" and password= "password",
2. create a database called "sa77bk"
3. create table "loginlog" which I have used in this script
To create a table use the script given below
create a table called loginlog for you use
create table loginlog(
username varchar(10) not null ,
logintime datetime);
insert into loginlog values('rajendra','1996-10-10 12:10:55');
insert into loginlog values('rajendra','1996-10-10 13:10:55');
insert into loginlog values('rajendra','1996-10-10 13:10:56');
insert into loginlog values('rajendra','1996-10-10 13:10:54');
insert into loginlog values('rajendra','1996-10-10 13:10:30');
insert into loginlog values('rajendra','1996-10-10 13:10:53');
insert into loginlog values('rajendra','1996-10-10 13:10:52');
insert into loginlog values('rajendra','1996-10-10 13:10:51');
insert into loginlog values('rajendra','1996-10-10 13:10:50');
insert into loginlog values('rajendra','1995-10-10 13:10:55');
insert into loginlog values('rajendra','1991-10-10 13:10:55');
insert into loginlog values('rajendra','1980-10-10 13:10:55');
insert into loginlog values('rajendra','1996-10-10 13:10:55');
insert into loginlog values('rajendra','1990-10-10 13:10:55');
insert into loginlog values('rajendra','1991-10-10 13:10:55');
*/
function db_connect($user, $dbase)
{
//change here if you changed the name of localhost and password
$dblink =@mysql_pconnect("localhost", $user, "password")or die("could not connect
to
the user or localhost");;
if (!$dblink)
{
return false;
}
if (!($db=mysql_select_db($dbase) or die("could not select the database")))
{
return false;
}
list($dblink, $db)=array($dblink,$db);
return array($dblink, $db);
}
//The following line shows the usage
//list($dblink, $db)=db_connect("sa77bk", "sa77bk");
//change here if you changed the user and database name
list($dblink, $db)=db_connect("sa77bk", "sa77bk");
$startrow = 0; //This variable says which is the starting row number
$perpage=8; //This variable says how many records should be diaplayed
in one page
$totalrecords=10;
//$query = "select * from loginlog where username='rajen' limit
$startrow,$totalrecords " ;
$query = "select * from loginlog where username='rajen'" ;
if (!isset($page))
{
$page=1;
$result = mysql_query($query, $dblink ) or die ("Database error");
$num_rows=mysql_num_rows($result);
// get the Number of pages
//$totalpagesreal=($totalrecords/$perpage);
$totalpagesreal=($num_rows/$perpage);
//print("<br>");
//print("totalpagesreal=$totalpagesreal");
//$totalpages=intval($totalrecords/$perpage);
$totalpages=intval($num_rows/$perpage);
//print("<br>");
//print("totalpages=$totalpages");
//If there are no records it gives the error message of There are no
records
if (($totalpages==$totalpagesreal) and ($totalpages==0) )
{
echo "There are no records";
$id=1;
//print("id=$id");
// print("<br>");
//print("total pages=");
//print($totalpages);
// print("<br>");
}
else
{
//Checks if there are records which exactly fits in the
integer
//number of pages
if (($totalpages==$totalpagesreal) and ($totalpages!=0))
{
$totalpages=$totalpages;
//print($totalpages);
$id=2;
print("<br>");
//print("id=$id");
// print("<br>");
}
//if there are
else
{
//print("<br>");
$id=3;
//print("id=$id");
//print("<br>");
$totalpages=$totalpages+1;
//print($totalpages);
//print("<br>");
}
}
}
/****************************************/
else
{
$page=$page;
$result = mysql_query($query, $dblink ) or die ("Database error");
$num_rows=mysql_num_rows($result);
// get the Number of pages
// $totalpagesreal=($totalrecords/$perpage);
$totalpagesreal=($num_rows/$perpage);
// $totalpages=intval($totalrecords/$perpage);
$totalpages=intval($num_rows/$perpage);
if (($totalpages==$totalpagesreal) and ($totalpages==0) )
{
echo "There are no records";
$id=1;
//print("id=$id");
// print($totalpages);
}
else
{
if (($totalpages==$totalpagesreal) and ($totalpages!=0))
{
$totalpages=$totalpages;
//print($totalpages);
$id=2;
//print("<br>");
//print("id=$id");
}
else
{
$id=3;
//print("id=$id");
//print("<br>");
$totalpages=$totalpages+1;
//print($totalpages);
}
Matt Weil wrote :708
A search but could be modified...
if($submitted) {
if ((!$str)){$msg = "Please Enter Something! Null searches are not good!! <a href=?page=search&str=microsoft&submitted=1>Microsoft</a> should return a few records.";}
else {
require("config.inc");
$offset=15;
if (!isset($min)) $min=0;
if (!isset($max)) $max=$min+$offset;
$str = stripslashes($str);
$sql = "SELECT keywords, name, title, des, html FROM pages where keywords LIKE \"%$str%\" OR name LIKE \"%$str%\" OR des LIKE \"%$str%\" OR title LIKE \"%$str%\" OR html LIKE \"%$str%\" ORDER BY title DESC limit $min,$offset";
$result = @mysql_query($sql,$connection) or die("Couldn`t execute query.1");
$num = mysql_numrows($result);
$x=0;
//$msg = "Found $num Entry Matching your Query";
if ($num == 0) {$msg = "No Entries found Please try again<br>";
}
while ($row = mysql_fetch_array($result)) {
$keywords = $row[`keywords`];
$name = $row[`name`];
$title = $row[`title`];
$des = $row[`des`];
$search_result .= "<p><a href=$url_base$name><strong>$title</strong></a><br><em>$des</em></p>";
$x++;
}
$prev=$min-$offset;
if ($prev>=0) {$prev_url = "<a href=?page=search&str=$str&min=$prev&submitted=1><-Previous Matches</a>";}
else {$prev_url = "";}
$next=$min+$offset;
if ($x>=14) {$next_url = "<a href=?page=search&str=$str&min=$max&submitted=1>Next Matches-></a>";}
else {$next_url = "";}
}
echo "<p>$msg</p>";
echo $search_result;
echo "<center>$prev_url $next_url</center>";
}