Table pagination example PHP
by Adrian on Feb.08, 2009, under Programming
Table Pagination in PHP can be easily achieved with this function.
It is designed to be used in conjunction with the database class found here but can be used standalone with any suitable array.
The idea of this function is to quickly output the results of a multi-dimensioned associative array, with the minimuim of fuss.
This is ideal for repetitive back office dutys, but however, there are arguments which can be passed depending upon the level of control required to change the functionality or format.
A beginners step by step example can be found here
and the source code here
Database class for php
by Adrian on Jan.07, 2009, under Programming
Database class for php
$dataBase = new DB();
(instaniates the database ready for CRUD)
$result = $dataBase->getQuery(‘SELECT * FROM FOO WHERE bar=1′);
($result contains a multidimensional associative array)
$id = $dataBase->setQuery(‘DELETE FROM FOO WHERE bar=1′);
($id contains the row id of the last update, can be left out)
To settup the class
1 2 3 4 5 6 7 8 9 10 | // database define ('HOST', 'localhost'); define ('NAME', 'NAME_OF_DATABASE'); define ('USER', 'USER_NAME'); define ('PASS', 'PASSWORD'); // Error messages define ('ERRS', false); // Meaningfull error messages on or off (mainly SQL related) define ('MESSAGE', 'The server encountered an internal error');// Default message define ('admin_email', 'someone@somewhere.com');// email errors to |
Errors can be set to display on or off (uses a generic message) it then emails full details to the administrator of the fault.
It can be downloaded from here
Code below
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 | <?php class DB{ /* DESCRIPTION: Object class, Handles all database requests and returns content accordingly WRITER: Adrian Callaghan 120808 INSTANIATION: new DB() requires HOST,NAME,USER,PASS,ERRS,MESSAGE values to be set prior (config) API: MODIFIERS: setStateClose() // sets the mySql connection to close setQuery($arg) // executes a query without returning any results, used for insert, create etc, // returns the ID of the last auto-increment setErrMessage($err) // displays and emails, the sql error setDataBase($database) // sets dataBase, leave arg blank to set back to the default ACCESSORS: getQuery($arg) // executes sql query from $arg and returns result as a '2d assoc array' getStateOpen() // returns details about the currently open connection */ var $mySqlHost; var $dataBase; function __construct() { $this->mySqlHost = @mysql_connect(HOST, USER, PASS); if (!$this->mySqlHost) { $this->setErrMessage('Access Error','Error',mysql_error(),$SQL); } $this->setDataBase(); } // Accesors function getQuery($SQL){ // executes a query $result = @mysql_query($SQL); if (!$result) { $this->setErrMessage('Sql Error','Invalid query',mysql_error(),$SQL); } // create a 2D array of results $return = array(); while ($row = mysql_fetch_assoc($result)) $return[] = $row; return $return; } function getStateOpen(){ // returns an array of details about the open connection $return['DB']['host']=$this->mySqlHost; $return['DB']['database']=$this->dataBase; } // Modifiers function setDataBase($dataBaseName=NAME){ $this->dataBase = @mysql_select_db($dataBaseName,$this->mySqlHost); if (!$this->dataBase) { $this->setErrMessage('I/O Error','Error',mysql_error(),$SQL); } } function setStateClose() { // closes current connection mysql_close($mySqlHost); } function setQuery($SQL){ // executes a query without returning any results, used for insert, create etc, returns the ID of the last auto-increment $result = @mysql_query($SQL); if (!$result) { $this->setErrMessage('Sql Error','Invalid query',mysql_error(),$SQL); } $return = mysql_insert_id(); return $return; } function setErrMessage($message, $errName, $err, $SQL){ // displays and emails, the sql error if (ERRS){ ?> <h1 style='color="#444444;'><?php echo $message; ?></h1> <hr> <p> <font color="#ff0000"><b><?php echo $errName; ?>: </b></font><?php echo $err; ?> <br /> <font color="#ff0000"><b>Whole query: </b></font><?php echo $SQL; ?> </p> <hr> <?php } else { ?> <h1 style='color="#444444;"'><?php echo MESSAGE; ?></h1> <hr> <?php } // email message $Name = $_SERVER['SERVER_NAME']; //senders name $email = "noreply@".$_SERVER['SERVER_NAME']; //senders e-mail adress //mail body $mail_body = '<h2>'.$_SERVER['SERVER_NAME'].' error</h2>'. $err.'<br/>'. '<h2>Request details</h2>'. '<b>Script filename and query string: </b>'.$_SERVER['SCRIPT_FILENAME'].'?'.$_SERVER['QUERY_STRING'].'<br/>'. '<b>Server name: </b>'.$_SERVER['SERVER_NAME'].'<br/>'. '<h2>User details</h2>'. '<b>IP ADDRESS: </b>'.$_SERVER['REMOTE_ADDR'].' : '.$_SERVER['REMOTE_PORT'].'<br/>'. '<b>Time: </b>'.date("D dS M,Y h:i a").'<br/>' ; $subject = $_SERVER['SERVER_NAME']." Error"; //subject $header = 'MIME-Version: 1.0' . "\r\n"; $header.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $header.= "From: ". $Name . " <" . $email . ">\r\n"; // send mail, and die $sent = @mail(admin_email, $subject, $mail_body, $header) ; if ($sent) $display.='<h2>The administrator has been notified</h2>'; else $display.='<h2>Please notify the administrator '.admin_email.'</h2>'; $display.='<p>Please call back again later</p>'; die($display); } } ?> |
clikStats
by Adrian on Dec.29, 2008, under Programming, wordpress
clikStats is a wordpress plugin that automatically detects the current links within each post.
ClikStats is retrofitable, and requires no special provision from any classes or code.
Once activated, clikStats will compile who, when, what data which can be viewed through the back office.
The beauty of this plugin is in its portability, it can be used straight out of the box, and provide usefull visitor information, without the need to reverse engineer your posts.
Download the latest version (v0.7) of clikStats from here
Simply add the unzipped folder to your pluggins folder, and make it active to start logging clicks.
Have fun
| RELEASE NOTES | |
|---|---|
| v0.3 04.01.09 | Provision for pagenation, deletion and better url parsing |
| v0.4 05.01.09 | Required update, due to a naming convention issue |
| v0.5 18.01.09 | Fixed security issues, enhanced UI, extra pages Big thankyou to Alexandre Araújo for his testing |
| v0.6 15.02.09 | Added search and some nice aesthetics |
| v0.7 09.05.09 | Added clik page/post sourcename, improved date filter system |
Some of the best reviews
VanSantos
Daily Seo Blog
Haunting thunder
Tech Ravings
THUK Media
General discussion RSS Feed