WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP Update Picture
Raj shrestha
Date : Sep 21st 2001
Grade : 5 of 5 (graded 1 times)
Viewed : 10667
File : spantable.php
Images : No Images for this code example.
Search : More code by Raj shrestha
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?

/*

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
GroupIT Engine v1.00rc1
Categories : PHP, Content Management, MySQL, Databases
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
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
Email a user with out exposing email address
Categories : PHP, Databases, MySQL, Email
Required form fields that pull from MySQL database
Categories : PHP, HTML and PHP, Databases, MySQL
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
Multiple Search using PHP and Mysql
Categories : PHP, Databases, General SQL, MySQL
List people whose birthdays fall on the current Day and Month
Categories : Databases, Date Time, MySQL, PHP
A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Function to do live population of HTML's <Select> tag from a Table
Categories : PHP, MySQL, HTML and PHP, Databases
This script is a contact form between users of a website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps
SQL / PHP based Integrated Authentication
Categories : PHP, Authentication, Databases, MySQL
Invision Forums Latest Threads list
Categories : PHP, Miscellaneous, 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!! &lt;a href=?page=search&str=microsoft&submitted=1&gt;Microsoft&lt;/a&gt; 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&lt;br&gt;";
}
while ($row = mysql_fetch_array($result)) {
        $keywords = $row[`keywords`];
        $name = $row[`name`];
        $title = $row[`title`];
        $des = $row[`des`];
        $search_result .= "&lt;p&gt;&lt;a href=$url_base$name&gt;&lt;strong&gt;$title&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;&lt;em&gt;$des&lt;/em&gt;&lt;/p&gt;";
        $x++;
        }
$prev=$min-$offset;
if ($prev&gt;=0) {$prev_url = "&lt;a href=?page=search&str=$str&min=$prev&submitted=1&gt;&lt;-Previous Matches&lt;/a&gt;";}
else {$prev_url = "";}
$next=$min+$offset;
if ($x&gt;=14) {$next_url = "&lt;a href=?page=search&str=$str&min=$max&submitted=1&gt;Next Matches-&gt;&lt;/a&gt;";}
else {$next_url = "";}
}
echo "&lt;p&gt;$msg&lt;/p&gt;";
echo $search_result;
echo "&lt;center&gt;$prev_url $next_url&lt;/center&gt;";
}