I have some existing code that I want to modify to limit the display
results to 5 rows and
add nav buttons to display the next set of 5, etc. You all know what I am
looking for.
I have a book- MySQL/PHP Database Applications by Greenspan & Bulger -
which has
an example that should work, but isn't. I have inserted the function from
the book and can
get 5 rows on the first page, and the next button, but the second page
doesn't display any
rows. Pasted below is the code for my page, the function in question is
down aways. I am
just learning this stuff, so don't be too hard on me about the existin
code, it works fine with-
out the nav function. I am sure there are probably more efficient ways to
write this, but for
now I just want to get the nav function to work properly.
(some lines will undoubtedly wrap and make it all look real ugly)
$conn = @mysql_connect("localhost","root") or die ("could not connect to the server");
mysql_select_db("bulletins", $conn) or die ("could not get the database");

function authenticate ($realm="Secure Area",$errmsg="Please enter a usename and 
header("WWW-Authenticate: Basic realm=\"$realm\"");
header("HTTP/1.0 401 Unauthorized");

if (empty($PHP_AUTH_USER))
$query = "select name from users where password = ('$PHP_AUTH_PW') and name = 
$result = mysql_query($query);
if ($result) { list($valid_user) = mysql_fetch_row($result); }
if (!$result || empty($valid_user))

    <meta name="generator" content="HTML Tidy, see www.w3.org" />
    <title>Dealer Bulletins, Simrad, Inc</title>
<style type="text/css">
 body {
  background-color: #b5e4f9;

    <center><h1>Simrad Dealer Bulletins</h1></center>
    <br />

    <p>You can sort the bulletins in the following order:<br />
          <font size="-1">(This will display all bulletins in one long page.)<br />
          OR click on the bulletin subject line below (much quicker)</font>

        <a href="bulletin_sorter.php?orderby=date">Bulletin Date</a> (oldest to newest)

        <a href="bulletin_sorter.php?orderby=date2">Bulletin Date</a> (newest to 

        Select bulletins from <a
        href="bulletin_sorter.php?orderby=vlad">Brian Vlad</a> - Plotter and
        Radar Products

        Select bulletins from <a
        href="bulletin_sorter.php?orderby=burke">Tom Burke</a> - Autopilots and

        Select bulletins from <a
        href="bulletin_sorter.php?orderby=hillers">Mike Hillers</a> -
<br />
    <br />
          <form name="form1" action="bulletin_sorter.php" method="post">
          Enter a word to search for: <input type="text" size="30" name="search"><br />
          <input type="submit" name="submit" value="Search">
          <font size="-1">(You must press the search button to complete the 
          <br />
          $result1 = mysql_query("select count(*) from dbulletins") or 
          echo "There are " .mysql_result($result1,0,0). " Bulletins listed in the 
          <br /><br />
    <hr width="75%" noshade="noshade" />

    <table summary="" border="0" cellpadding="5" align="center" width="90%">
      $db = mysql_connect("localhost", "root");
      mysql_select_db("bulletins", $db);

      if ($orderby == 'date'):
      $sql = "select * from dbulletins order by 'bulletin_date'";
      elseif ($orderby == 'date2'):
      $sql = "select * from dbulletins order by 'bulletin_date' desc";
      elseif ($orderby == 'vlad'):
      $sql = "select * from dbulletins where bulletin_from1 like '%Vlad%' order by 
'bulletin_number' desc";
      elseif ($orderby == 'burke'):
      $sql = "select * from dbulletins where bulletin_from1 like '%Burke%' order by 
'bulletin_number' desc";
      elseif ($orderby == 'hillers'):
      $sql = "select * from dbulletins where bulletin_from1 like '%Hillers%' order by 
'bulletin_number' desc";
               elseif (isset($submit)):
               $sql = "select * from dbulletins where match (body) against 
      $sql = "select * from dbulletins order by 'bulletin_date' desc";

      $result2 = mysql_query($sql);

      while ( $row = mysql_fetch_array($result2))
                if ($orderby == 'vlad' || $orderby == 'burke' || $orderby == 'hillers' 
|| $orderby =='date' || $orderby == 'date2' || $search
== 'orderby'):
             print("<tr>\n<td colspan=\"2\">\n<img src=\"1pixb5e4f9.gif\" alt=\"\" 
height=\"20\" width=\"1\">\n</td>\n</tr>");
             print("<tr>\n<td bgcolor=\"white\" colspan=\"2\">\n<strong>\n");
             printf("<font color=\"blue\">%s</font>\n</strong>\n</td>\n</tr>\n", 
             print("<tr>\n<td valign=\"top\">\n<h2 class=\"c1\">\n<br />Dealer 
             printf("<strong>Date:</strong> %s\n", $row["bulletin_date"]);
             printf("<br />\n<strong>Number:</strong> %s\n", $row["bulletin_number"]);
             printf("<br />\n<strong>Subject:</strong> %s\n", 
             printf("<br />\n<strong>From:</strong> %s<br />%s\n", 
$row["bulletin_from1"], $row["bulletin_from2"]);
             print("</td>\n<td valign=\"top\" align=\"left\">\n");
                               print("<font face=\"Arial Black\" 
             print("<br />\n<font size=\"3\">&nbsp;&nbsp;&nbsp;A 
<strong>KONGSBERG</strong> Company</font>\n</center>\n");
             print("<br />Simrad Inc.\n");
             print("<br />19210-33<sup>rd</sup> Avenue West, Suite A\n");
             print("<br />Lynnwood, WA 98036\n");
             print("<br />U.S.A.\n");
             print("<br />Telephone: 1-425-778-8821\n");
             print("<br />Telefax: 1-425-771-7211\n");
             print("<br />\n<br />\n</td>\n</tr>");
             printf("<tr>\n<td colspan=2>%s\n", $row["body"]);
             print("<br />\n<hr width=\"75%\" />\n");
        printf("<tr><td>* <a 
/>&nbsp;&nbsp;&nbsp;%s</td></tr>", $row
["bulletin_subject"], $row["bulletin_date"], $row["bulletin_from1"]);
function nav($offset=0,$this_script="bulletin_sorter.php")
      global $php_self;
      $page_limit = 5;
      if (empty($this_script)) { $this_script = $php_self; }
      if (empty($offset)) { $offset = 0; }
      $result3 = mysql_query("select count(*) from dbulletins");
      list($total_rows) = mysql_fetch_array($result3);
      print "<p>\n";
     if ($offset > 0 )
     print "<a 
href=\"$this_script?offset=".($offset-page_limit)."\">&lt;&lt;Previous</a> &nbsp; ";
     if ($offset+page_limit < $total_rows)
     print "<a href=\"$this_script?offset=".($offset+page_limit)."\">Next&gt;&gt;</a> 
&nbsp; ";
      print "</p>\n";

Thanks for any help you all can provide,

Chip Wiegand
Computer Services
Simrad, Inc
Lynnwood, WA

"There is no reason anyone would want a computer in their home."
 --Ken Olson, president, chairman and founder of Digital Equipment Corp.,
          (-- Then why do I have nine? Somebody help me!)

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to