Re: [PHP] Page display of query resuts using ODBC

2002-12-11 Thread Tom Rogers
Hi,

Wednesday, December 11, 2002, 2:05:25 AM, you wrote:
LR Hi,

LR Just wondering if anybody knows a script to display a resultset over several pages 
using page numers  previous, next links.

LR So far I've only found such scripts for mysql using the the following sql syntax 
which is not odbc compliant: SELECT * from table LIMIT 0, 4

LR I've looked at many sites to find such a script without luck so far...

LR Thanks in advance for your help,

LR -Luc
Here is a paging class I wrote, it is using mysql but the example is not using
the LIMIT feature so it should work with a little change for odbc.

?
class page_class {
var $count = 0; //total pages
var $start = 0; //starting record
var $pages = 0; //number of pages available
var $page = 1;  //current page
var $maxpages;  //shows up to 2 * this number and makes a sliding scale
var $show;  //number of results per page
function page_class($count=0,$show=5,$max=9){
$this-count = $count;
$this-show = $show;
$this-maxpages = $max;
($this-count % $this-show == 0)? $this-pages = 
intval($this-count/$this-show) :$this-pages = intval($this-count/$this-show) +1;
if(!empty($_GET['search_page'])){
$this-page = $_GET['search_page'];
$this-start = $this-show * $this-page -$this-show;
}
}
function get_limit(){
$limit = '';
if($this-count  $this-show) $limit = 
'LIMIT'.$this-start.','.$this-show;
return $limit;
}
function get_start(){
 return $this-start;
}
function get_end(){
 return ($this-start + $this-show);
}
function make_head_string($pre){
$r = $pre.' ';
$end = $this-start + $this-show;
if($end  $this-count) $end = $this-count;
$r .= ($this-start +1).' - '.$end.' of '.$this-count;
return $r;
}
function make_page_string($words,$pre='Result Page:'){
$r = $pre.' ';
if($this-page  1){
$y = $this-page - 1;
$r .= 'a 
href='.$_SERVER['PHP_SELF'].'?search_page='.$y.$words.'Previous/anbsp;';
}
$end = $this-page + $this-maxpages-1;
if($end  $this-pages) $end = $this-pages;
$x = $this-page - $this-maxpages;
$anchor = $this-pages - (2*$this-maxpages) +1;
if($anchor  1) $anchor = 1;
if($x  1) $x = 1;
if($x  $anchor) $x = $anchor;
while($x = $end){
if($x == $this-page){
$r .= 'span class=s'.$x.'/spannbsp;';
}
else{
$r.= 'a 
href='.$_SERVER['PHP_SELF'].'?search_page='.$x.$words.''.$x.'/anbsp;';
}
$x++;
}
if($this-page  $this-pages){
$y = $this-page + 1;
$r .= 'a 
href='.$_SERVER['PHP_SELF'].'?search_page='.$y.$words.'Next/anbsp;';
}
return $r;
}
}

//Usage
$searchword = 'MSIE';
$whatever = 'user=me';
mysql_connect(localhost, user, pw..) or die (mysql_error());

$Query = SELECT COUNT(*) AS cnt FROM db.table WHERE agent LIKE '% .$searchword. %';
if(!$result = mysql_query($Query)){
echo 'oops: '.mysql_error();
exit;
}
$row = mysql_fetch_array($result);
$count = $row['cnt'];

if($count  0){
  //start class total number of results,number of results to show,max number of 
pages on a sliding scale (ends up as 2x this number..ie 20)
$page = new page_class($count,5,10); 
$start = $page-get_start();
$end = $page-get_end();
$Query2= SELECT * FROM db.table WHERE agent LIKE '%.$searchword. %' ORDER BY  
time_stamp ASC ;
$result = mysql_query($Query2) or die(mysql_error());
$hstring = $page-make_head_string('Results');
$pstring = 
$page-make_page_string(amp;searchword=.$searchword.amp;whatever=.$whatever);//add
 the other variables to pass to next page in a similar fashion
echo tabletrtd.$hstring./td/tr;
$x = 0;
while($row = mysql_fetch_array($result)){
  if($x = $start){
echo 'trtd'.$x.' '.$row['agent'].' '.$row['time_stamp'].'/td/tr';
  }
  $x++;
  if($x  $end) break;
}
echo 'trtd'.$pstring.'/td/tr/table';
}
//Note: the search variables on subsequent pages will be passed by GET method
?



-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re[2]: [PHP] Page display of query resuts using ODBC

2002-12-11 Thread Tom Rogers
Hi,

Wednesday, December 11, 2002, 8:02:41 PM, you wrote:
TR Hi,

TR Wednesday, December 11, 2002, 2:05:25 AM, you wrote:
LR Hi,

LR Just wondering if anybody knows a script to display a resultset over several 
pages using page numers  previous, next links.

LR So far I've only found such scripts for mysql using the the following sql syntax 
which is not odbc compliant: SELECT * from table LIMIT 0, 4

LR I've looked at many sites to find such a script without luck so far...

LR Thanks in advance for your help,

LR -Luc
TR Here is a paging class I wrote, it is using mysql but the example is not using
TR the LIMIT feature so it should work with a little change for odbc.

TR ?
TR class page_class {
TR var $count = 0; //total pages
TR var $start = 0; //starting record
TR var $pages = 0; //number of pages available
TR var $page = 1;  //current page
TR var $maxpages;  //shows up to 2 * this number and makes a sliding 
scale
TR var $show;  //number of results per page
TR function page_class($count=0,$show=5,$max=9){
TR $this-count = $count;
TR $this-show = $show;
TR $this-maxpages = $max;
TR ($this-count % $this-show == 0)? $this-pages = 
intval($this-count/$this-show) :$this-pages = intval($this-count/$this-show) +1;
TR if(!empty($_GET['search_page'])){
TR $this-page = $_GET['search_page'];
TR $this-start = $this-show * $this-page -$this-show;
TR }
TR }
TR function get_limit(){
TR $limit = '';
TR if($this-count  $this-show) $limit = 
'LIMIT'.$this-start.','.$this-show;
TR return $limit;
TR }
TR function get_start(){
TR  return $this-start;
TR }
TR function get_end(){
TR  return ($this-start + $this-show);
TR }
TR function make_head_string($pre){
TR $r = $pre.' ';
TR $end = $this-start + $this-show;
TR if($end  $this-count) $end = $this-count;
TR $r .= ($this-start +1).' - '.$end.' of '.$this-count;
TR return $r;
TR }
TR function make_page_string($words,$pre='Result Page:'){
TR $r = $pre.' ';
TR if($this-page  1){
TR $y = $this-page - 1;
TR $r .= 'a 
href='.$_SERVER['PHP_SELF'].'?search_page='.$y.$words.'Previous/anbsp;';
TR }
TR $end = $this-page + $this-maxpages-1;
TR if($end  $this-pages) $end = $this-pages;
TR $x = $this-page - $this-maxpages;
TR $anchor = $this-pages - (2*$this-maxpages) +1;
TR if($anchor  1) $anchor = 1;
TR if($x  1) $x = 1;
TR if($x  $anchor) $x = $anchor;
TR while($x = $end){
TR if($x == $this-page){
TR $r .= 'span class=s'.$x.'/spannbsp;';
TR }
TR else{
TR $r.= 'a 
href='.$_SERVER['PHP_SELF'].'?search_page='.$x.$words.''.$x.'/anbsp;';
TR }
TR $x++;
TR }
TR if($this-page  $this-pages){
TR $y = $this-page + 1;
TR $r .= 'a 
href='.$_SERVER['PHP_SELF'].'?search_page='.$y.$words.'Next/anbsp;';
TR }
TR return $r;
TR }
TR }

TR //Usage
TR $searchword = 'MSIE';
TR $whatever = 'user=me';
TR mysql_connect(localhost, user, pw..) or die (mysql_error());

TR $Query = SELECT COUNT(*) AS cnt FROM db.table WHERE agent LIKE '% .$searchword. 
%';
TR if(!$result = mysql_query($Query)){
TR echo 'oops: '.mysql_error();
TR exit;
TR }
TR $row = mysql_fetch_array($result);
TR $count = $row['cnt'];

if($count  0){
TR   //start class total number of results,number of results to show,max number 
of pages on a sliding scale (ends up as 2x this number..ie 20)
TR $page = new page_class($count,5,10); 
TR $start = $page-get_start();
TR $end = $page-get_end();
TR $Query2= SELECT * FROM db.table WHERE agent LIKE '%.$searchword. %' ORDER 
BY  time_stamp ASC ;
TR $result = mysql_query($Query2) or die(mysql_error());
TR $hstring = $page-make_head_string('Results');
TR $pstring = 
$page-make_page_string(amp;searchword=.$searchword.amp;whatever=.$whatever);//add
 the other variables to pass to next page in a similar fashion
TR echo tabletrtd.$hstring./td/tr;
TR $x = 0;
TR while($row = mysql_fetch_array($result)){
TR   if($x = $start){
TR echo 'trtd'.$x.' '.$row['agent'].' '.$row['time_stamp'].'/td/tr';
TR   }
TR   $x++;
TR   if($x  $end) 

[PHP] Page display of query resuts using ODBC

2002-12-10 Thread Luc Roettgers
Hi,

Just wondering if anybody knows a script to display a resultset over several pages 
using page numers  previous, next links.

So far I've only found such scripts for mysql using the the following sql syntax which 
is not odbc compliant: SELECT * from table LIMIT 0, 4

I've looked at many sites to find such a script without luck so far...

Thanks in advance for your help,

-Luc