Login   Register  
PHP Classes
elePHPant
Icontem

File: db_example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Eugene Olkhovick  >  eoPaginator  >  db_example.php  >  Download  
File: db_example.php
Role: Example script
Content type: text/plain
Description: Example of eoPaginator+MySQL usage
Class: eoPaginator
Generate navigation for listings split among pages
Author: By
Last change:
Date: 2009-11-23 01:05
Size: 1,755 bytes
 

Contents

Class file image Download
<?php
require ("eoPaginator.php");

define("db_server","127.0.0.1");
define("db_name","cars");
define("db_user","");
define("db_passwd","");

if (isset(
$_GET["cur_page"])) {$cur_page=$_GET["cur_page"];} else {$cur_page=1;}


/* Making connection to server and selecting database */
$db_conn=mysql_pconnect(db_server,db_user,db_passwd) or die(mysql_error());
mysql_select_db(db_name) or die(mysql_error());

/* Total quantity of records definition */
$total_recs=mysql_num_rows(mysql_query("SELECT ID FROM `tb_cars`",$db_conn));


$pag = new eoPaginator();
$pag->max_pages 5;
$pag->rec_per_page 5;
$pag->a_href="?cur_page=_PAGNUM_";
$pag->a_class="pag1";
$pag->a_sel_class="pag2";

$pag_array=$pag->make_pgr($total_recs,$cur_page);
$pag_block=implode("",$pag_array);

$query "SELECT * FROM `tb_cars` ".$pag->query_limit;

$r mysql_query($query,$db_conn) or die(mysql_error());

while (
$res=mysql_fetch_array($r))
{
 
$tbody_content .="<tr><td>".$res["ID"]."</td><td>".$res["VENDOR"]."</td><td>".$res["MODEL"]."</td></tr>";
}

$_html_block="<html>
<head>
 <title>eoPaginator + MySQL test page</title>
 <style>
  .pag1{font-family:Arial; text-decoration:none; color:black;}
  .pag2{font-family:Arial;  text-decoration:none; border:2px solid #CCCCCC;}
 </style>
</head>
<body>
<div style=\"width:100%; border:1px solid #CCCCCC\">"
.$pag_block."</div>
<br />
<div style=\"width:100%; border:1px solid #CCCCCC\">"
.$query."</div>
<br />
<table style=\"border: 1px solid #CCCCCC\">
 <thead style=\"background-color:#ECD672; font-family:Arial;\">
  <th>ID</th>
  <th>VENDOR</th>
  <th>MODEL</th>
 </thead>
 <tbody>"
.$tbody_content."
 </tbody>
</table>
</body>
</html>"
;

echo 
$_html_block;

?>