Link to home
Start Free TrialLog in
Avatar of havenboy
havenboy

asked on

Dreamweaver Navigation Bar Problem

HI,  I am fairly new to Dreamweaver CS3 and dynamic websites, I have been working non-stop this week and have several record sets set up and they are dynamically populating tables wth repeat region data from a PHP/MySQL database.

When I display an entire record set the records display correctly.

My problem is when I use a (text field) filter within Dreamweaver (currently single parameter) to define the recordset I want to display in my dynamic table the first page loads pefectly but using the navigation bar "forward arrow" the second page loads but the table results are empty.  And any subsequent forward/back arrow usage means empty tables as well.

I think this is because the variable I define as my text field (i.e. search term) to populate the table is not carrying over to the second page (via the nav button), any heplp on this issue wuld be much appreciated
Thank you in advance for any help offered
<?php require_once('Connections/connRecord.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
 
$maxRows_rsSearchResults = 40;
$pageNum_rsSearchResults = 0;
if (isset($_GET['pageNum_rsSearchResults'])) {
  $pageNum_rsSearchResults = $_GET['pageNum_rsSearchResults'];
}
$startRow_rsSearchResults = $pageNum_rsSearchResults * $maxRows_rsSearchResults;
 
$colname_rsSearchResults = "-1";
if (isset($_POST['search'])) {
  $colname_rsSearchResults = (get_magic_quotes_gpc()) ? $_POST['search'] : addslashes($_POST['search']);
}
mysql_select_db($database_connRecordGuide, $connRecordGuide);
$query_rsSearchResults = sprintf("SELECT `PRIMARY`, fld_artist_key, fld_title, fld_catalogue, fld_value_08 FROM tbl_albums WHERE fld_artist_key LIKE '%%%s%%'", $colname_rsSearchResults);
$query_limit_rsSearchResults = sprintf("%s LIMIT %d, %d", $query_rsSearchResults, $startRow_rsSearchResults, $maxRows_rsSearchResults);
$rsSearchResults = mysql_query($query_limit_rsSearchResults, $connRecordGuide) or die(mysql_error());
$row_rsSearchResults = mysql_fetch_assoc($rsSearchResults);
 
if (isset($_GET['totalRows_rsSearchResults'])) {
  $totalRows_rsSearchResults = $_GET['totalRows_rsSearchResults'];
} else {
  $all_rsSearchResults = mysql_query($query_rsSearchResults);
  $totalRows_rsSearchResults = mysql_num_rows($all_rsSearchResults);
}
$totalPages_rsSearchResults = ceil($totalRows_rsSearchResults/$maxRows_rsSearchResults)-1;
 
$queryString_rsSearchResults = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rsSearchResults") == false && 
        stristr($param, "totalRows_rsSearchResults") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rsSearchResults = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rsSearchResults = sprintf("&totalRows_rsSearchResults=%d%s", $totalRows_rsSearchResults, $queryString_rsSearchResults);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
<title>Untitled Document</title>
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 
 
 
 
 
 
<link href="Accessible_Design.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	background-color: #000000;
}
.style2 {color: #FFFFFF}
.style3 {color: #FF0000}
.style4 {color: #FF0000; font-size: small; }
-->
</style></head>
<body class="BodyBackgroundColor">
<img src="spacer.gif" alt="Skip to Content" width="1" height="1" />
<table width="100%" border="0" cellpadding="4" cellspacing="0">
  <tr>
    <td height="114" class="HeaderColor style2"><img src="" alt=" Thumbnail Image" name="image" width="100" height="81" id="image" /></td>
    <td width="100%" class="HeaderColor style2"><table width="573" border="1" cellpadding="2" cellspacing="1" bordercolor="#FF0000">
      <tr valign="bottom" bordercolor="#FF0000">
        <td width="573" class="NavigationBackgroundColor" style="text-align: center"><a href="rrpg_advsearch.html" class="style4">Advanced Search </a> </td>
        <td width="573" class="NavigationBackgroundColor" style="text-align: center"><a href="rrpg_forums.html" class="style4">Forums</a> </td>
        <td width="573" class="NavigationBackgroundColor" style="text-align: center"><a href="rrpg_grading.html" class="style4">Grading/Glossary</a> </td>
        <td width="573" class="NavigationBackgroundColor" style="text-align: center"><a href="rrpg_faq.html" class="style4">FAQ</a> </td>
        <td width="573" class="NavBackgroundColor" style="text-align: center"><a href="rrpg_contactus.html" class="style4">Contact Us </a> </td>
      </tr>
    </table>
        <table width="573" height="25" border="1" bordercolor="#FF0000">
          <tr align="left" valign="top">
            <th width="263" height="38" scope="col"><div align="left">
                <form id="searchart" name="searchart" method="get" action="rrpg_results.php">
                  Artist
                  <label for="textfield"></label>
                  <input type="text" name="search" id="search" />
                  <label for="Submit"></label>
                  <input type="submit" name="Submit" value="Go" id="Submit" />
              </form>
            </div></th>
            <th width="257" scope="col"><form id="searchtit" name="searchtit" method="post" action="rrpg_resultstit.php">
                <label for="label"></label>
              Title
              <input type="text" name="searchtitle" id="label" />
              <label for="label2"></label>
              <input type="submit" name="Submit2" value="Go" id="label2" />
            </form></th>
          </tr>
      </table></td>
  </tr>
</table>
<p class="style2">&nbsp;</p>
 
<table border="1" cellpadding="2" cellspacing="2">
  <tr align="center" valign="top">
    <td height="25"><span class="style2 style2 style3">Record No. </span></td>
    <td height="25"><span class="style3">Artist Key </span></td>
    <td height="25"><span class="style3">Title</span></td>
    <td height="25"><span class="style3">Catalogue</span></td>
    <td height="25"><span class="style2">Value</span></td>
  </tr>
  <?php do { ?>
    <tr>
      <td><span class="style2"><a href="rrpg_detail.php?recordID=<?php echo $row_RsRecordTable['PRIMARY']; ?>"><?php echo $row_rsSearchResults['PRIMARY']; ?></a></span></td>
      <td><span class="style2"><?php echo $row_rsSearchResults['fld_artist_key']; ?></span></td>
      <td><span class="style2"><?php echo $row_rsSearchResults['fld_title']; ?></span></td>
      <td><span class="style2"><?php echo $row_rsSearchResults['fld_catalogue']; ?></span></td>
      <td><span class="style2"><?php echo $row_rsSearchResults['fld_value_08']; ?></span></td>
    </tr>
    <?php } while ($row_rsSearchResults = mysql_fetch_assoc($rsSearchResults)); ?>
</table>
<p class="style2"> Records <?php echo ($startRow_rsSearchResults + 1) ?> to <?php echo min($startRow_rsSearchResults + $maxRows_rsSearchResults, $totalRows_rsSearchResults) ?> of <?php echo $totalRows_rsSearchResults ?>
<table border="0" width="50%" align="center">
  <tr>
    <td width="23%" align="center"><?php if ($pageNum_rsSearchResults > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_rsSearchResults=%d%s", $currentPage, 0, $queryString_rsSearchResults); ?>"><img src="First.gif" border=0></a>
        <?php } // Show if not first page ?>
    </td>
    <td width="31%" align="center"><?php if ($pageNum_rsSearchResults > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_rsSearchResults=%d%s", $currentPage, max(0, $pageNum_rsSearchResults - 1), $queryString_rsSearchResults); ?>"><img src="Previous.gif" border=0></a>
        <?php } // Show if not first page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_rsSearchResults < $totalPages_rsSearchResults) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_rsSearchResults=%d%s", $currentPage, min($totalPages_rsSearchResults, $pageNum_rsSearchResults + 1), $queryString_rsSearchResults); ?>"><img src="Next.gif" border=0></a>
        <?php } // Show if not last page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_rsSearchResults < $totalPages_rsSearchResults) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_rsSearchResults=%d%s", $currentPage, $totalPages_rsSearchResults, $queryString_rsSearchResults); ?>"><img src="Last.gif" border=0></a>
        <?php } // Show if not last page ?>
    </td>
  </tr>
</table>
</p>
first page ?>
          First
</td>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm, the search form submits using GET: -
<form id="searchart" name="searchart" method="get" action="rrpg_results.php">

Yet the colparam snippet is expecting POST vars.
if (isset($_POST['search'])) {
  $colname_rsSearchResults = (get_magic_quotes_gpc()) ? $_POST['search'] : addslashes($_POST['search']);
}

I recon changing the colparam to GET would do the trick, because then this lil snippet transferrs the search value to via the querystring:
  if (count($newParams) != 0) {
    $queryString_rsSearchResults = "&" . htmlentities(implode("&", $newParams));
  }

So, all you would have to do is change the colparam code...
if (isset($_GET['search'])) {
  $colname_rsSearchResults = (get_magic_quotes_gpc()) ? $_GET['search'] : addslashes($_GET['search']);
}

Open in new window

ie - jason's #1
>> Hmm, the search form submits using GET:

There are two forms.  One is using POST, the other GET:

<form id="searchart" name="searchart" method="get" action="rrpg_results.php">

<form id="searchtit" name="searchtit" method="post" action="rrpg_resultstit.php">

So now I'm a little confused as to which is which.
Deep hole Alice.
I think we are using this form:

<form id="searchart" name="searchart" method="get" action="rrpg_results.php">

as it has the "search" field in it.  However, since that form is GET, the rsSearchResults recordset shouldn't work at all since it is looking for a POST variable.  So I'm not sure what you are seeing, havenboy.

Also, not a part of this question but I just noticed this:

SELECT `PRIMARY`,

You really, really should not name your columns using MySQL reserved words.  Dreamweaver will attempt to escape them for you but will not always be successful.
Avatar of havenboy
havenboy

ASKER

Guys, you are absolute legends, I am going to try this now, sorry for the late reply but I am on UK time.  As soon as I correct this I will add on the accepted answer as well.

I will go for otion #1 from your guidance I have only been working with Dreanweaver and PHP for about 4 days so I think it will be easier for me a this stage.

The reason for the two form submits "search" and searchtit" is becuase I have two seperate forms searching two seperate columns in my database from the same page (they achieve the same result though), I have the feeling that this is not the best way of doing this and I should be able to achieve this through a single piece of code, but like I say I am just warming up!!

Once I get the right result I wil be changing both of them to the answer given in any case.

Thank you again for your help, I wll be back on soon.

I have tested this and it works perfectly.  I had juggled the settings so many times trying to get this right and to have a quick response that is clear and concise, writen by an expert is invaluable.  Thank you to everyone who posted replies to my query.  Once again I extend my appreciation for your response.

The reason that I was getting results using the seperate POST and GET statements in the same code, was because I was trying all sorts of variations to try and get it to tie up with the mutiltude of different web searches and forums I had tried previously (i.e. the code I posted was not the nearest I had got to correct code, but it showed the mess I got into trying to attempt different variations on the POST and GET commands/URL and FORM variables).  Your response was perfect it meant I could go back in with a clear path in my mind of how to use these commands, and not only that but means that the principles behind the reasoning and struture of perfroming these actions is also now clear.

Many, many thanks