First off I read through the below article from the beginning. I do have a better understanding of OOP in PHP that what I did before today but am stillhaving some problems. With the article on screen I proceeded to adapt the script accordingly to what I need done.

URL=http://www.sitepoint.com/article/php-paging-result-sets/5]OOP Pagination on Sitepoint[/URL]

My guess is as good as yours but I tracked the problem down to the while loop in my cresults.php file. I am getting the table, but none of the variables are coming through from the database and I know that I am connected.

[PHP
<?
include('inc/connect.inc');
include('pagedresults.php');
$table = "fwcems";
$limit = 10;

$totalrows = mysql_result(mysql_query("SELECT count(cem_id) FROM $table"),0);
$limitvalue = $page * $limit - ($limit);
if($totalrows == 0)
{
echo("Nothing to Display!");
}

$rs = new MySQLPagedResultSet("select * from fwcems where $stype LIKE $search",10,$connection);
echo "<HTML>";
echo "<head>";
echo "<title>".$ptitle."</title>";
echo "</head>";
echo "<body background=img/clouds.jpg bgproperties=fixed>";
echo "<CENTER>";
echo "<H1 align=center>Cemetery Search</H1>";
echo "<table border=0 width=50%>";
while ($row=$rs->fetchArray());

echo "<tr>";
    echo "<td align=center colspan=2><Q>";
    echo $row[1]." Cemetery</Q>";
    echo "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td align=center colspan=2>";
    echo "<Q>Located at ".$row[3]."</Q>";
    echo "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td align=center>";
    echo "Status: ";
    echo "</td>";
    echo "<td align=center>";
    echo $row[2];
    echo "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td align=center>";
    echo "Owner: ";
    echo "</td>";
    echo "<td align=center>";
    echo $row[4];
    echo "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td align=center>";
    echo "Phone #: ";
    echo "</td>";
    echo "<td align=center>";
    echo $row[5];
    echo "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td align=center>";
    echo "E-mail address: ";
    echo "</td>";
    echo "<td align=center>";
    echo $row[6];
    echo "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td align=center colspan=2>";
    echo "<HR color=#AA00FF>";
    echo "</td>";
echo "</tr>";

echo "</table>";
$rs->getPageNav(" cem_id=$cem_id");
echo "</center>";
echo "</body>";
echo "</html>";
?>
[/code]

Your urgent response is greatly appreciated.

Sincerely;

KB9YJG

P.s. You can download the class file that was worked on in the article but I myself have caught only one variation in the sets of code.

    while ($row=$rs->fetchArray());

    Well that does nothing because of the semicolon after the while, basically it repeats nothing however many rows there are.

    Plus all that echoing is bad batch - use heredoc, just type that into google and you'll be all - ahhhh, that's nice.

      <? 
      include('inc/connect.inc');
      include('pagedresults.php');
      $table = "fwcems";
      $limit = 10;                
      $totalrows = mysql_result(mysql_query("SELECT count(cem_id) FROM $table"),0); $limitvalue = $page * $limit - ($limit); $rs = new MySQLPagedResultSet("select * from fwcems where $stype LIKE $search",10,$connection); if($totalrows == 0) { echo("Nothing to Display!"); } echo <<< HTML <HTML> <head> <title>$ptitle</title> </head> <body background=img/clouds.jpg bgproperties=fixed> <CENTER> <H1 align=center>Cemetery Search</H1> <table border=0 width=50%> HTML; while ($row=$rs->fetchArray()) { echo <<< HTML <tr> <td align=center colspan=2><Q> $row[1] Cemetery</Q> </td> </tr> <tr> <td align=center colspan=2> <Q>Located at $row[3] </Q> </td> </tr> <tr> <td align=center> Status: </td> <td align=center> $row[2] </td> </tr> <tr> <td align=center> Owner: </td> <td align=center> $row[4] </td> </tr> <tr> <td align=center> Phone #: </td> <td align=center> $row[5] </td> </tr> <tr> <td align=center> E-mail address: </td> <td align=center> $row[6] </td> </tr> <tr> <td align=center colspan=2> <HR color=#AA00FF> </td> </tr> HTML; } echo "</table>"; $rs->getPageNav("cem_id=$cem_id"); ?> </center> </body> </html>

      Sorry but im still not getting any output. as a matter of fact i believe the problem is still in that while loop and still no content from the variables.

        Are you definitely getting results from your
        MySQLPagedResultSet function

        As you've got:

        select * from fwcems where $stype LIKE $search

        Does the variable $search already have single quotes in it, as LIKE queries have the comparison quoted

        SELECT * FROM somewhere WHERE field LIKE 'foo';

        Where are your $stype and $search variables coming from? Are they form variables and you have register globals on, or have you skipped the details as they're trivial?

        Won't be around for a while... sleep needed for vampire boys.

          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>&nbsp;</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;
            }
          }
          ?>
          
            Write a Reply...