I am not sure if I am or not. This is my second attempt at learning oop and took a
tutorial from sitepoint.com on OOP based pagination.
http://www.sitepoint.com/article/php-paging-result-sets
but there seem to be some differences in the code this site offers to download and
what is in the actual article/tutorial.
Well I get the $search and $stype variables from a form. $stype is a dropdown box
with values of the fields in the database table. $search is a textbox for the user
to put in certain search terms. The main reason I have the query as follows:
select * from fwcems where $stype LIKE $search
is because I want the user to be able to set the dropdown box to search for the name
of,the owner,status either open or closed,address a cemetery. What I was trying to
achieve is using the like $search with the wildcard symbol which I am not sure of.
I tried to use % and ? but those failed to work either. I am not sure but I think
register globals is on.
Thanks for your help.
I am posting my form code below I have all the variables defined in another php file
in wich the form below is used via include function..
Sincerely;
😃
kb9yjg
jmbllm@yahoo.com
<center>
<form method=post action=<? echo $respage; ?>>
<table border=0>
<tr>
<th>Search By:</th><th>Search For:</th><th> </th>
</tr>
<tr>
<td align=center>
<select name=stype>
<option value=<? echo $optv1; ?>><? echo $opt1; ?>
<option value=<? echo $optv2; ?>><? echo $opt2; ?>
<option value=<? echo $optv3; ?>><? echo $opt3; ?>
<option value=<? echo $optv4; ?>><? echo $opt4; ?>
<!--<option value=<? echo $optv5; ?>><? echo $opt5; ?>
<option value=<? echo $optv6; ?>><? echo $opt6; ?>
<option value=<? echo $optv7; ?>><? echo $opt7; ?>
<option value=<? echo $optv8; ?>><? echo $opt8; ?>-->
</select>
</td>
<td align=center>
<input type=text name=search size=50 maxsize=55>
</td>
<td align=left>
<input type=submit value=Search!>
<input type=hidden value=$search>
<input type=hidden value=$stype>
</td>
</tr>
</table>
</form>
</center>
Here is also the class that I have been trying to get working.
<?php
include('inc/connect.inc');
class MySQLPagedResultSet
{
var $resultpage
var $results;
var $pageSize;
var $page;
var $row;
function MySQLPagedResultSet($query,$pageSize,$onnection)
{
global $resultpage = $_GET['resultpage'];
$this->results = @mysql_query($query,$onnection);
$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 = '')
{
$nav = '';
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;
}
}
?>