473,394 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Displaying dbase content

I am retreiving information from a database and it works ok, but its
rather a lot and I like to limit each web page to 10 rows of data,
then put the next ten on a new web page, probably with a back|forward
buttons at the bottom.

Problem is I really not sure how to do this any would hoping someone
could throw me some advice!

Cheers!!
Jul 16 '05 #1
2 2360
in your file that you want the pager on:

<?php

require_once('pagedresults.php');

$cnx = @mysql_connect('localhost','user','password');
mysql_select_db('database',$cnx);
$rs = new MySQLPagedResultSet("select statement to database", 10,$cnx);
//10 is number of thingies to pull through

if(!$rs) die(mysql_error());
?>
//save the following into 'pagedresults.php'
when you want to call the navigator simply call it with

$rs->getPageNav();

and then you can format the results of $rs as you see fit :)
<?php

class MySQLPagedResultSet
{

var $results;
var $pageSize;
var $page;
var $row;

function MySQLPagedResultSet($query,$pageSize,$cnx)
{
global $resultpage;

$this->results = @mysql_query($query,$cnx);
$this->pageSize = $pageSize;
if ((int)$resultpage <= 0) $resultpage = 1;
if ($resultpage > $this->getNumPages())
$resultpage = $this->getNumPages();
$this->setPageNum($resultpage);
}

function getNumPages()
{
if (!$this->results) return FALSE;

return ceil(mysql_num_rows($this->results) /
(float)$this->pageSize);
}

function setPageNum($pageNum)
{
if ($pageNum > $this->getNumPages() or
$pageNum <= 0) return FALSE;

$this->page = $pageNum;
$this->row = 0;
mysql_data_seek($this->results,($pageNum-1) * $this->pageSize);
}

function getPageNum()
{
return $this->page;
}

function isLastPage()
{
return ($this->page >= $this->getNumPages());
}

function isFirstPage()
{
return ($this->page <= 1);
}

function fetchArray()
{
if (!$this->results) return FALSE;
if ($this->row >= $this->pageSize) return FALSE;
$this->row++;
return mysql_fetch_array($this->results);
}

function getPageNav($queryvars = '')
{
if (!$this->isFirstPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()-1).'&'.$queryvars.'">Prev</a> ';
}
if ($this->getNumPages() > 1)
for ($i=1; $i<=$this->getNumPages(); $i++)
{
if ($i==$this->page)
$nav .= "$i ";
else
$nav .= "<a href=\"?resultpage={$i}&".
$queryvars."\">{$i}</a> ";
}
if (!$this->isLastPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()+1).'&'.$queryvars.'">Next</a> ';
}

return $nav;
}
}

?>
David wrote:
I am retreiving information from a database and it works ok, but its
rather a lot and I like to limit each web page to 10 rows of data,
then put the next ten on a new web page, probably with a back|forward
buttons at the bottom.

Problem is I really not sure how to do this any would hoping someone
could throw me some advice!

Cheers!!


Jul 16 '05 #2
I can get the code you gave me to display the first 10 results but the
navbar at the bottom refuses to work, and I get a notice telling me

Notice: Undefined variable: nav in c:\program files\apache
group\apache\htdocs\drivemasters\pagedresults.php on line 75

The URL seems to suggest it is working

http://localhost/Drivemasters/pictur...irstname=david

but the content displayed on this page is exactly the same as page 1
so clearly it hasnt worked!

any ideas???
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Goldfisch1980 | last post by:
Hi! I read an dBase table under Win XP by the common dBase functions of PHP 4.3.5. But all records are displayd with a wrong charset. All umlauts of the databasefile like "öäüéô"... and so on...
4
by: Matt Young | last post by:
I've been tasked with integrating an older management system based on DBF files with my snappy new ASP application to provide users of the ASP application with real-time data from the management...
2
by: Ivan | last post by:
Hi, SQL Server 2000 SP3 Windos 2000 Server SP4 I have a DTS package that imports data from a dBase IV databse with files located in two folders (dBF1 and dBF2). I use a transform data task...
14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
1
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for...
2
by: Songyang | last post by:
I'm new to this group. In my company in Japan, we have been using dbase for almost 20 years, and we are now switching to foxpro. Dose anybody here has experience in converting dbase programs from...
2
by: bcbrock | last post by:
I am trying to figure out how to query some data out of a dbase IV (.dbf) file sitting on a remote server from my MySQL/PHP/Web Server. Both servers are Windows Server 2003 SP2. My...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.