|
|
|
<?
/*
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);
}
}
}
print("<table border='1' width='50%'>");
for($n=($startrow+($page-1)*$perpage); $n<($startrow+($page)*$perpage);$n++)
{
// print($n);
print("<tr>");
print("<td>");
@print(mysql_result($result,$n,0));
print("</td>");
print("<td>");
@print(mysql_result($result,$n,1));
print("</td>");
print("</tr>");
//print("<BR>");
}
print("</table>");
for($i=1 ; $i<=$totalpages; $i++)
// for($i=1 ; $i<=3; $i++)
{
//print("<br>");
print("<A href=spantable.php?page=".$i.">");
print("page".$i);
print("</A>");
print("|\t");
}
?> |
|
| bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | MySQL database class Categories : PHP, MySQL, Databases, PHP Classes | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | A Simple sign up script with PHP and JavaScript validations. Categories : PHP, Java Script, MySQL, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | phpEasySQL - Easily connect to your MySQL database with just 1 php file and 3 easy steps! Categories : Databases, PHP, MySQL, General SQL | | | free, search engine, indexing, system, information, web,
ftp, http, free, software, cgi, php, MySQL, database, php3,
FreeBSD, Linux, Unix, UdmSearch Categories : MySQL, Complete Programs, PHP, Databases, Search | | | Full membership authentication system. Categories : Authentication, MySQL, PHP, Databases | | | Example voting script. Lets people enter suggestions and vote for existing ones. Categories : MySQL, PHP, Cookies, Complete Programs, Databases | | | Required form fields that pull from MySQL database Categories : PHP, HTML and PHP, Databases, MySQL | | | Ajax PHP Tree (Left and Right) with MySQL Categories : PHP, Databases, MySQL, AJAX, PHP Classes | | | YellowPages Content Grabber (PHP5 +) Categories : PHP, PHP Classes, Regexps, Databases, MySQL | |
| | | | 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>";
}
| |
|
|