How to Add an Admin User to the WordPress Database via MySQL


Deprecated: Function create_function() is deprecated in /home/ursaftwz/public_html/myscripthub.com/wp-content/plugins/codecolorer/lib/geshi.php on line 4698
1
2
3
4
INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('500', 'badmin', MD5('demo'), 'admin', 'test@yourdomain.com', 'http://www.test.com/', '', '', '0', 'admin');

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '500', 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '500', 'wp_user_level', '10');

HTML and web design

What is HTML

HTML, or HyperText Markup Language, is a world wide markup language that allows a user to create his or her own web page. While HTML is a fairly easy to learn markup language, it does involve several hundred commands to learn and memorize.

With HTML, the user creates tags; tags are anything between the less-than and the greater-than signs. Using the tags, this identifies where the commands begin and end. For example, <b>Bold Text</b> tells the browser that <b> is the beginning of the bold text statement that will turn anything after that tag bold; once the browser hits </b> the browser then turns the bold text statement off, allowing for only specific text to be bold

On this page we have created a list of HTML commands, which can be used in web pages to change text, add different features, and apply several other different effects.

<!– REMARK –>  

HTML Tag that allows you to implement comments into your HTML Code, Hide contents on browser.

Example:
<!– This text Cannot be seen by the user unless the source is viewed. –>

<A>

tag that allows aspects of your web page to be anchored, such as a link <A HREF= “http://scriptforyou.com”>
Example:
<A HREF=”http://scriptforyou.com”>ScriptForYou</A>

<ACRONYM>

Like ABBREV, also a new command with HTML 3.0 that displays the text acronym when mouse is highlighted over text.
Example:
<ACRONYM TITLE=”Free script help”>ScriptForyou</ACRONYM>

<ADDRESS>

Command that changes the format of the text to signify an address. This is used with e-mail addresses. However, can also be used for a street address.
Example:
<ADDRESS>exemple@scriptforyou.com</ADDRESS>

<APPLET>

Command used  to implement a Java application into a web page.
Example:
<APPLET CODE=”myapplet”>Click here to see Java applet.</APPLET>

<AREA>

Defines a section of an image that the user can click on. This allows you to have one image with multiple clickable links within it.
Example:
<map name=”map”>
<AREA SHAPE=rect COORDS=”100,5,155,55″ HREF=”http://www.scriptforyou.com”>
</map>
<img src=”exemple.gif” usemap=”#map”>

<B>

Tells the browser to display the text within the HTML tags to be bold.
Example:
<B>This text would be in bold</B>

<BANNER>

 HTML Tag used with HTML 3.0 used like scrolling but does not scroll with the rest of the HTML document.
Example:
<BANNER>Script For You</BANNER>

<BASEFONT>

Tells the browser the new set for the font size can be 1 through 7. The default value is 3.
Example:
<BASEFONT SIZE=2>

<BDO>

Tells the browser how to display the text; for example, using the DIR attribute you can make it go left to right using DIR=ltr Example: <BDO DIR=rtl>Makes text go opposite way<bdo> this just causes the text to go right to left; this tag is usually used for international purpose.
Example:
<BDO DIR=ltr>This text would be going from the left to the right.</BDO>

<BGSOUND>

Allows you to play your music on your web page with Internet Explorer; will not work with people browsing with Netscape. You may also add the loop= statement to specify how many times you wish the sound to play.
Example:
<BGSOUND SRC=sounds.wav loop=1>

 <BIG>

HTML 3.0 tag that allows your text to be BIG.
Example:
<BIG>This text would be big.</BIG>

<BLINK>

HTML tag that can be extraordinarily annoying when viewing a web page. Internet Explorer does not incorporate this tag, but still is available with Netscape Navigator,firefox etc.
Example:
<BLINK>This text would be blinking if compatible browser</BLINK>

<BLOCKQUOTE>

Command that allows you to indent your lines one inch from the left hand side. Instead of using this command to indent text or other objects we suggest using CSS.
Example:
<BLOCKQUOTE>This would be one tab from the left hand side of the page or the table cell it is in.</BLOCKQUOTE>

<BODY>

Command that should be located towards the top of your HTML code. This tag is used to specify the color of the text, the links, the background color and the background image.
Example:
<body background=”back.gif” bgcolor=”#FFFFFF” text=”#000000″ link=”#000000″ vlink=”#000000″ alink=”#000000″ topmargin=”0″ leftmargin=”0″>

<BR>

Tells the browser that this is the end of the line and to start a new one.
Example:
Welcome <BR>  to <br> scriptforyou

 <CENTER>

Tells the web browser to center the text according to the page, table, or frame.
Example:
<CENTER>This text would center on the page.</CENTER>

<CITE>

Similar to the blockquote command this command enables you to cite text and displays itself in an italic font.
Example:
<CITE>This text is in italic and is a cite from somewhere else.</CITE>

<CODE>

Allows the user to specify code or a command that generates a different font to signify the code.
Example:
<CODE>htmt use various tags</CODE>

<DEL>

Allows a user to delete text within an HTML document without actually removing it using a strike through.
Example:
This is an example of <del>removed</del> text.

<DD>

Specifies to the browser that a definition is going to placed in the code.
Example:
<DD>Definition</DD>

<EM>

Tells the browser that this is important text and it will make it emphasized.
Example:
<EM>Script for you </EM>

<EMBED>

Use to implements a third-party file such as a movie or sound clip or some special embedded object on the web page.
Example:
<EMBED SRC=”resume.doc”>

<FONT>

 Allows you to have multiple fonts, colors and sizes.
Example 1:
< font size=+2>This text would be two times bigger.</ font >
Example 2:
< font COLOR=”BLUE”>This text would be blue.</ font >
Example 3:
< font COLOR=”RED”>This text would be red.</ font >
Example 4:
< font COLOR=”YELLOW”>This text would be yellow.< /font>

<FORM>

Allows you to obtain input from visitors.

<FRAME>

It allows you to use frames on the web page, being able to make bigger and smaller sections; each frame can contain different text. You can also use the <FRAMESET command, which is a replacement for the regular body command.>
Example:
<FRAM SRC=”http://scriptforyou.com” SCROLLING=”yes” NORESIZE>

<H1> <H2>  <H3>  <H4>  <H5>  <H6>

Tells the browser how big you want the text <H1> being the biggest and <H6> being the smallest. Note: Because Computer Hope is using CSS elements for the H1 tag not only will this text be big but it will have an underline in this example. Without the CSS it would just be big.
Example:
<H1>This text would be BIG.</H1>
Example:
<H6>This text needs spectacles to read.</H6>

 <HEAD>

Allowing you to tell about the web page but this info will never be displayed when viewing unless the source is viewed, as well as the location to place your meta tags.
Example:
<HEAD><TITLE>Look at the top of the page how it says HTML HELP, specify the name you want the page to be.</TITLE></HEAD>

 <HR>

Puts a normal bar across the screen to help separate the text.
Example 1:

Hello world<HR>

<I>

Italicizes the text.
Example:
<I>Italic Text</I>

<IMG>

Command used to display images on your web page.
Example:
<IMG SRC= “logo.gif”>

<INS>

Short for Insert, this tag is used to help illustrate what new text has been inserted into an HTML document. Useful for when multiple people are working on the same document.
Example:
This line of text has <INS>new</INS> inserted text.

<ISIndex>

New command coming out with HTML 3.0 allowing you to search.
Example:
<ISIndex>

<LI>

Tells the browser that this is a list item, either putting a bullet in front of text or a number in front of the text, depending if <ul> or <ol> is used.
Example:
<ul>
<li>one</li>
<li>two</li>
</ul>
Example 2:
<ol>
<li>one</li>
<li>two</li>
</ol>

 <MARQUEE>

Make your text scroll on the screen.
Example 1:
<MARQUEE BEHAVIOR=”scroll” DIRECTION =”left”>Script for you</MARQUEE>

<META>

Allowing you to tell some search engines what to display for your page and keywords for your page.
Example 1:
<META NAME=”DESCRIPTION” CONTENT=”script for you help to find solution of you problem “>
Example 2:
<META NAME=”KEYWORDS” CONTENT=”yii,html,php,css”>
Example 3:
<META NAME=”GENERATOR” CONTENT=”Generated in Notepad”>

<TITLE>

This is used to label the page that your on. For example, the name of this page is ONLINE HELP -HTML-, Usually shown at the top of your screen.
Example:
<TITLE>HTML HELP</TITLE>

<NOBR>

Tells the browser that you want to continue the line with no breaking, preventing the line from getting cut of and returning to the next line.
Example:
<NOBR>This line would go on and not auto return so if the browser screen was not as long as the sentence you would have to scroll to see the remainder of the screen.</NOBR>

<OL>

Tells the browser that this is a list item and to list it in numbering format.
Example:
<ol>
<li>one</li>
<li>two</li>
</ol>

<UL>

Starts a bulleted item list (puts a bullet in front of text).
Example:
<ul>
<li>one</li>
<li>two</li>
</ul>

<SELECT>

Select menu that allows their person viewing your web page to select from a menu.
Example:
<select name=”List” size=”1″>
<option value=”Option1″>Option1</option>
<option value=”Option2″>Option2</option>
<option value=”Option3″>Option3</option>
</select>

<OPTGROUP>

Add an option groups to a drop down list of items.
Example:
<select name=”Example”>
<optgroup label=”First”></optgroup>
<option>Example one</option>
<optgroup label=”Second”></optgroup>
<option>Example two</option>
</select>

 <P>

Tells the browser that this is the end of the paragraph and will not attempt to word wrap it.
Example:
<P>Location for the paragraph to begin and end.</P>

<PRE>

Tells the browser to do what you do as you type it so you can put text where you want it and have as many spaces as you want.
Example:
<PRE>here is my code.</pre>

<SAMP>

Will enclose the text as a sample, usually lower casing it and underlining it.
Example:
<SAMP>This would be small and plain.<SAMP>

<STRONG>

Putting the text bold.
Example:
<STRONG>Script for you</STRONG>

<SUB>

Subscript; makes the browser display text low.
Example:
<SUB>This text would be below midway.<SUB>

<SUP>

Superscript; makes the browser display text high.
Example:
<SUP>This text would be above midway.<SUP>

<TABLE>

Allows you to Align text in tables. You can see an example of this on our Support page. How you do this is start with <Table> and if you want borders, just use the below commands.
Example:
<TABLE ALIGN=”center” border=1 cols=5 width=20 cellpadding=5><tr><td>Computer Hope</td></tr></TABLE>

 <TR>

The start of each row in a table. See table page for additional information and examples on tables.
Example:
<TR><TD>Table contents</TD></TR>

<TH>

This is what each cell on the table is using.You can make this contain as many cells as you need.
Example:
<TH VALIGN=”middle” WIDTH=50>Table header</TH>

<TT>

Tells the browser that the font needs to be evenly spaced to occupy the full line.
Example:
<TT>This would be displayed as teletype</TT>

<TD>

Used to define each cell part of the table. See table page for additional information and examples on tables.
Example:
<TD ALIGN=”center” WIDTH=20>Cell</TD>

<TEXT AREA>

Allows the user to input text.
Example:
<TEXTAREA NAME=”text” COLS=20 ROWS=20></TEXTAREA>

 

PHP Introduction

What is PHP? 

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

  • PHP stands for PHP: Hypertext Preprocessor.
  • It is a server-side scripting language.
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.).
  •  PHP is an open source software and  free to download and use

What is a PHP File?

  • PHP files can contain text, HTML tags and scripts other words it contain both server side or client side language
  • PHP files are returned to the browser as plain HTML .
  • PHP files extension  .php, .php3  or.phtml

What is MySQL?

MySQL is a open source Relational Database Management System. MySQL is very fast reliable and flexible Database Management System. It provides a very high performance and it is multi threaded and multi user Relational Database management system.

MySQL are very fast and much reliable for any type of application.
MySQL is very Lightweight application.
MySQL command line tool is very powerful and can be used to run SQL queries against database.
MySQL Supports indexing and binary objects.
It is allow changes to structure of table while server is running.
MySQL has a wide user base.
It is a very fast thread-based memory allocation system.
MySQL Written in C and C++ language.
MySQL code is tested with different compilers.
MySQL is available as a separate program for use in a client/server network environment.
The MySQL available for the most Unix operating platform.
MySQL are the available for window operating system window NT, window 95 ,and window 98.
MySQL available for OS/2.
Programming libraries for C, Python, PHP, Java , Delphi etc. are available to connect to MySQL database.

PHP + MySQL 

PHP combined with MySQL are cross-platform  you can develop in Windows and serve on a Unix platform.

Resize the image unlimited times without losing the original image’s quality

 

1. Create image.php  File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php

class Image {

private $data = false; // the original - never changes
private $width;
private $height;
private $type;
private $image; // created and updated in $this->resize()

public function url ($website) {
$website = str_replace(' ', '%20', trim($website));
if ($info = @getimagesize($website)) {
switch ($info[2]) {
case 1: $this->type = 'gif'; break;
case 2: $this->type = 'jpg'; break;
case 3: $this->type = 'png'; break;
default: return false; break; // image type not supported
}
$this->width = $info[0];
$this->height = $info[1];
$data = file_get_contents ($website);
if ($data !== FALSE) {
$this->data = $data;
return true;
}
}
return false;
}

public function type () {
$type = '';
if (!empty($this->type)) $type = '.' . $this->type;
return $type;
}

public function convert ($type) {
if (in_array($type, array('jpg', 'gif', 'png'))) {
$this->type = $type;
return $this->resize();
}
return false;
}

public function resize ($width='', $height='') { // constrains proportions within $width and $height
if ($this->data === FALSE) return false;
if (empty($width)) {
$width = $this->width;
$height = $this->height;
} else {
list ($width, $height) = $this->proportional ($width, $height);
}
$this->image = ''; // to clean the slate if necessary
$this->image = @imagecreatefromstring($this->data);
$image = imagecreatetruecolor ($width, $height);
if ($this->type == 'png') {
imagealphablending ($image, false);
imagesavealpha ($image, true);
$transparent = imagecolorallocatealpha ($image, 255, 255, 255, 127);
imagefilledrectangle ($image, 0, 0, $width, $height, $transparent);
} else {
$white = imagecolorallocate ($image, 255, 255, 255);
imagefilledrectangle ($image, 0, 0, $width, $height, $white);
}
imagecopyresampled ($image, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
$this->image = $image;
return true;
}

public function square ($pixels) { // generates a square image of $pixels size
if ($this->data === FALSE) return false;
$width = $height = $pixels;
$x = $y = 0;
$size = $this->width;
if ($this->height > $this->width) {
$y = round(($this->height - $this->width) / 2);
} elseif ($this->width > $this->height) {
$x = round(($this->width - $this->height) / 2);
$size = $this->height;
}
$this->image = ''; // to clean the slate if necessary
$this->image = @imagecreatefromstring($this->data);
$image = imagecreatetruecolor ($width, $height);
if ($this->type == 'png') {
imagealphablending ($image, false);
imagesavealpha ($image, true);
$transparent = imagecolorallocatealpha ($image, 255, 255, 255, 127);
imagefilledrectangle ($image, 0, 0, $width, $height, $transparent);
} else {
$white = imagecolorallocate ($image, 255, 255, 255);
imagefilledrectangle ($image, 0, 0, $width, $height, $white);
}
imagecopyresampled ($image, $this->image, 0, 0, $x, $y, $width, $height, $size, $size);
$this->image = $image;
return true;
}

public function save ($location, $quality=80) {
if (!is_dir(dirname($location))) mkdir(dirname($location), 0755, true);
if (!empty($this->image)) {
if ($this->type == 'jpg') {
return imagejpeg ($this->image, $location, $quality);
} elseif ($this->type == 'gif') {
return imagegif ($this->image, $location);
} elseif ($this->type == 'png') {
if ($quality >= 90) {
$quality = 0;
} else {
$quality = abs(round($quality / 10) - 9);
}
return imagepng ($this->image, $location, $quality);
}
} elseif (!empty($this->data)) {
if (file_put_contents ($location, $this->data)) return true;
}
return false;
}

public function display ($quality=80) {
if (!empty($this->image)) {
if ($this->type == 'jpg') {
header ('Content-type: image/jpeg');
return imagejpeg ($this->image, NULL, $quality);
} elseif ($this->type == 'gif') {
header ('Content-type: image/gif');
return imagegif ($this->image);
} elseif ($this->type == 'png') {
if ($quality >= 90) {
$quality = 0;
} else {
$quality = abs(round($quality / 10) - 9);
}
header ('Content-type: image/png');
return imagepng ($this->image, NULL, $quality);
}
} elseif (!empty($this->data)) {
switch ($this->type) {
case 'jpg': header ('Content-type: image/jpeg'); break;
case 'gif': header ('Content-type: image/gif'); break;
case 'png': header ('Content-type: image/png'); break;
}
echo $this->data;
return true;
}
return false;
}

private function proportional ($width, $height) {
if (empty($height)) $height = $width * .8;
$use = (($width / $height) <= ($this->width / $this->height)) ? 'width' : 'height';
$max_dimension = ($use == 'width') ? $width : $height;
$ratio = ($this->width >= $this->height) ? $max_dimension / $this->width : $max_dimension / $this->height;
if($this->width > $max_dimension || $this->height > $max_dimension) {
$width = round($this->width * $ratio);
$height = round($this->height * $ratio);
} else { // the resize is larger than the original
$width = round($this->width);
$height = round($this->height);
}
return array ($width, $height);
}

}

?>

2. Include  image.php

include_once(‘image.php’);

3.  Creates a new image object

$image = new Image;

 3.1. Opens an image resource from specified website

1
$image->url ('http://www.somesite.com/images/copy.jpg');

3.2 covert image gif  to  jpg

1
$image->convert ('jpg');

3.3  resize the original image within the width and height specified without losing the original image’s quality

1
2
3
4
5
resize ( integer $width [, integer $height ] ) //width in pixel,height in pixel

$image->resize (500);

$image->resize (600,500);

3.4 Generate a square image

1
$image->square (80); // size in pixel

3.5 save an image 

1
$image->save ('/images/copied.jpg');

3.6 Display image directly to the browser

1
$image->display (80);

 

 

Mysql Easily insert and update records

1.Create a database.php file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

define ('DB_SERVER', 'localhost');
define ('DB_USERNAME', 'username');
define ('DB_PASSWORD', 'password');
define ('DB_DATABASE', 'database');

$mysqli = new mysqli (DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);

if (mysqli_connect_errno()) {
trigger_error ('DB Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
exit ('Sorry! We were unable to connect to the database. Please try again.');
}

function escape_data ($data) {
global $mysqli;
if (get_magic_quotes_gpc()) $data = stripslashes($data);
return $mysqli->real_escape_string(trim($data));
}

function db_query ($query) {
global $mysqli;
if (!$result = $mysqli->query ($query)) trigger_error("Query: {$query}<br />Error: {$mysqli->error}");
return $result;
}

function db_insert ($table, $array) {
global $mysqli;
$unquote = array('NULL', 'NOW()');
foreach ($array as $key => $value) {
$columns[] = $key;
if (is_numeric($value) || in_array($value, $unquote)) {
$data[] = $value;
} else {
$data[] = "'{$value}'";
}
}
db_query ('INSERT INTO `' . $table . '` (`' . implode('`, `', $columns) . '`) VALUES (' . implode(', ', $data) . ')');
return $mysqli->insert_id;
}

function db_update ($table, $array, $column, $id, $add='') {
global $mysqli;
$unquote = array('NULL', 'NOW()');
foreach ($array as $key => $value) {
if (is_numeric($value) || in_array($value, $unquote)) {
$data[] = '`' . $key . '`=' . $value;
} else {
$data[] = '`' . $key . "`='{$value}'";
}
}
$id = (is_numeric($id)) ? $id : "'{$id}'";
db_query ("UPDATE `{$table}` SET " . implode(', ', $data) . " WHERE `{$column}`={$id} {$add}");
return $mysqli->affected_rows;
}

?>

2. include  database.php

include_once ( ‘database.php’);

2.1. Insert Query use function  

db_insert ( string $table, array $array )

1
2
3
4
5
6
$insert = array();
$insert['name'] = 'username';  //insert['table column name']='value you want insert'];
$insert['password'] = 'password';
$insert['email'] = 'email@address.com';
$insert['registered'] = 'NOW()';
$userid = db_insert('users', $insert);

2.2.Update Query use function 

db_update ( string $table, array $array, string $column, mixed $id [, string $add ] )

1
2
3
4
5
$update = array();

$ update ['email'] = 'email@address.com';

db_update ('users', $update, 'user_id', 1);

2.3.Write query use function

db_query ( string $query )

1
2
3
4
$result = db_query ("SELECT data FROM table WHERE column='{$value}'");
while (list($data) = $result->fetch_row()) {
$html .= $data . '<br />';
}

2.4.Escape any problematic characters use function

escape_data ( string $data )

1
$username = escape_data ("Hacker'); hello;--");

 

Track inbound (internal links) traffic [wordpress plugin]

Track inbound (internal links) traffic of your site, Simply install plugin and change settings as you want.

Features:-

Track Visitors IP information, browser details, Refferel Urls, Destination Urls, Memory execution size, Executed Mysql queries, Execution Time.

You can track traffic of individual page/post by check/uncheck Enable traffic option in your page/post.

You can set tag for page/post from admin for sorting/searching track pages by tag.

Downloads Tracking report as Excel.

Enjoy:)

Tracking Inbound & Outbond traffic [wordpress plugin]

Track inbound and outbond traffic of your site, Simply install plugin and change settings as you want.

Features:-

Track Visitors IP information, browser details, Refferel Urls, Destination Urls.

You can track traffic of individual page/post by check/uncheck Enable traffic option in your page/post.

You can set tag for page/post from admin for sorting/searching track pages by tag.

Downloads Tracking report as Excel.

Open all outbond site urls on your website in frames (No need to send outbond links to new tab/new window).

Enjoy:)

 

Disable visual editor from post/pages wordpress plugin

Disable visual editor from post/pages wordpress plugin:

This plugin will disable the visual editor tab  for selected page/post. The idea came when i see whenever i updated the content in html tab it will show visual media editor again after updation but  i had to keep the html intact by the tinymce editor whenever i switched back to Visual tab in the editor.

== Installation ==

1. Upload directory `disableVisualEditor` to the `/wp-content/plugins/` directory
2. Activate the plugin.

How to disable/enable wysiwyg editor for page/post

Go to admin section where you add/edit new page/post and you will see small panel on the right called “Visual Editor” with a checkbox saying “Disable”. When you Click it and update the post, you will no longer be able to edit the page/post until you unclick and update the page/post.

Download!
Download!

 

 

Php pagination

Grab the code and paste in your text editor.
You have to customize 7 spots in this code (see images below).

1. Code to connect to your DB – place or include your code to connect to database.
2. $tbl_name – your table name.
3. $adjacents – how many adjacent pages should be shown on each side.
4. $targetpage – is the name of file ex. I saved this file as pagination.php, my $targetpage should be “pagination.php”.
5. $limit – how many items to show per page.
6. “SELECT column_name – change to your own column.
7. Replace your own while..loop here – place your code to echo results here.

After all, save and test your script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
    /*
        Place code to connect to your DB here.
    */

    include('config.php');  // include your code to connect to DB.

    $tbl_name="";       //your table name
    // How many adjacent pages should be shown on each side?
    $adjacents = 3;
   
    /*
       First get total number of rows in data table.
       If you have a WHERE clause in your query, make sure you mirror it here.
    */

    $query = "SELECT COUNT(*) as num FROM $tbl_name";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];
   
    /* Setup vars for query. */
    $targetpage = "filename.php";   //your file name  (the name of this file)
    $limit = 2;                                 //how many items to show per page
    $page = $_GET['page'];
    if($page)
        $start = ($page - 1) * $limit;          //first item to display on this page
    else
        $start = 0;                             //if no page var is given, set start to 0
   
    /* Get data. */
    $sql = "SELECT column_name FROM $tbl_name LIMIT $start, $limit";
    $result = mysql_query($sql);
   
    /* Setup page vars for display. */
    if ($page == 0) $page = 1;                  //if no page var is given, default to 1.
    $prev = $page - 1;                          //previous page is page - 1
    $next = $page + 1;                          //next page is page + 1
    $lastpage = ceil($total_pages/$limit);      //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1;                      //last page minus 1
   
    /*
        Now we apply our rules and draw the pagination object.
        We're actually saving the code to a variable in case we want to draw it more than once.
    */

    $pagination = "";
    if($lastpage > 1)
    {  
        $pagination .= "<div class="pagination">";
        //previous button
        if ($page > 1)
            $pagination.= "<a href="$targetpage?page=$prev">� previous</a>";
        else
            $pagination.= "<span class="disabled">� previous</span>";
       
        //pages
        if ($lastpage < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up
        {  
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class="current">$counter</span>";
                else
                    $pagination.= "<a href="$targetpage?page=$counter">$counter</a>";                  
            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))    //enough pages to hide some
        {
            //close to beginning; only hide later pages
            if($page < 1 + ($adjacents * 2))       
            {
                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class="current">$counter</span>";
                    else
                        $pagination.= "<a href="$targetpage?page=$counter">$counter</a>";                  
                }
                $pagination.= "...";
                $pagination.= "<a href="$targetpage?page=$lpm1">$lpm1</a>";
                $pagination.= "<a href="$targetpage?page=$lastpage">$lastpage</a>";    
            }
            //in middle; hide some front and some back
            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
            {
                $pagination.= "<a href="$targetpage?page=1">1</a>";
                $pagination.= "<a href="$targetpage?page=2">2</a>";
                $pagination.= "...";
                for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class="current">$counter</span>";
                    else
                        $pagination.= "<a href="$targetpage?page=$counter">$counter</a>";                  
                }
                $pagination.= "...";
                $pagination.= "<a href="$targetpage?page=$lpm1">$lpm1</a>";
                $pagination.= "<a href="$targetpage?page=$lastpage">$lastpage</a>";    
            }
            //close to end; only hide early pages
            else
            {
                $pagination.= "<a href="$targetpage?page=1">1</a>";
                $pagination.= "<a href="$targetpage?page=2">2</a>";
                $pagination.= "...";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class="current">$counter</span>";
                    else
                        $pagination.= "<a href="$targetpage?page=$counter">$counter</a>";                  
                }
            }
        }
       
        //next button
        if ($page < $counter - 1)
            $pagination.= "<a href="$targetpage?page=$next">next �</a>";
        else
            $pagination.= "<span class="disabled">next �</span>";
        $pagination.= "</div>\n";      
    }
?>

    <?php
        while($row = mysql_fetch_array($result))
        {
   
        // Your while loop here
   
        }
    ?>

<?=$pagination?>

CSS Mentioned below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
div.pagination {
    padding: 3px;
    margin: 3px;
}

div.pagination a {
    padding: 2px 5px 2px 5px;
    margin: 2px;
    border: 1px solid #AAAADD;
   
    text-decoration: none; /* no underline */
    color: #000099;
}
div.pagination a:hover, div.pagination a:active {
    border: 1px solid #000099;

    color: #000;
}
div.pagination span.current {
    padding: 2px 5px 2px 5px;
    margin: 2px;
        border: 1px solid #000099;
       
        font-weight: bold;
        background-color: #000099;
        color: #FFF;
    }
    div.pagination span.disabled {
        padding: 2px 5px 2px 5px;
        margin: 2px;
        border: 1px solid #EEE;
   
        color: #DDD;
    }

Code file after changes: