• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

Showing next record (page) with filter

Hi Experts, im using a url paramiter to display to my page from a data base but i need to show as a repeating region.
I need an sql stement that will show more records in that database. chapters that are taged with manual.
manual_id_book and id_manual are the common links.

my database is as follows

Recordset (adminchapters)
  id_book
  manual_id_book
  title_book
  revdate_book
  supercddate_book

Recordset (adminchapter2)
  id_manual
  name_manual
  id_level_manual

the url paramater from the chapter list is admin_chapters.php?id_book=1&id_manual=1
this diaplays the name_manual and the id_book but doesnt recoginize the other book associated with the particular manual.

Recordset (adminchapter1) is filtered as id_book = id_book
Recordset (adminchapter2) is filtered as id_manual = id_manual  as url paramiters.

i tried to filter Recordset (adminchapter1) as manual_id_book = id_manual, this sees the oter records in that manual but directs me to the first record.

im not good at all with sql statments what tis the best way to display only those records that are taged with that manual. here is the detail page im having problems with.

first page is the detail recoord set and the net is the list that shows the chapters in that manual.


<?php require_once('../../Connections/romarc.php'); ?>
<?php
// Require the MXI classes
require_once ('../../includes/mxi/MXI.php');

// Load the tNG classes
require_once('../../includes/tng/tNG.inc.php');

// Make unified connection variable
$conn_romarc = new KT_connection($romarc, $database_romarc);

//Start Restrict Access To Page
$restrict = new tNG_RestrictAccess($conn_romarc, "../../");
//Grand Levels: Level
$restrict->addLevel("3");
$restrict->Execute();
//End Restrict Access To Page

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_adminchapters = 1;
$pageNum_adminchapters = 0;
if (isset($_GET['pageNum_adminchapters'])) {
  $pageNum_adminchapters = $_GET['pageNum_adminchapters'];
}
$startRow_adminchapters = $pageNum_adminchapters * $maxRows_adminchapters;

$colname_adminchapters = "-1";
if (isset($_GET['id_book'])) {
  $colname_adminchapters = (get_magic_quotes_gpc()) ? $_GET['id_book'] : addslashes($_GET['id_book']);
}
mysql_select_db($database_romarc, $romarc);
$query_adminchapters = sprintf("SELECT * FROM chapters WHERE id_book = %s", $colname_adminchapters);
$query_limit_adminchapters = sprintf("%s LIMIT %d, %d", $query_adminchapters, $startRow_adminchapters, $maxRows_adminchapters);
$adminchapters = mysql_query($query_limit_adminchapters, $romarc) or die(mysql_error());
$row_adminchapters = mysql_fetch_assoc($adminchapters);

if (isset($_GET['totalRows_adminchapters'])) {
  $totalRows_adminchapters = $_GET['totalRows_adminchapters'];
} else {
  $all_adminchapters = mysql_query($query_adminchapters);
  $totalRows_adminchapters = mysql_num_rows($all_adminchapters);
}
$totalPages_adminchapters = ceil($totalRows_adminchapters/$maxRows_adminchapters)-1;

$colname_adminchapters2 = "-1";
if (isset($_GET['id_manual'])) {
  $colname_adminchapters2 = (get_magic_quotes_gpc()) ? $_GET['id_manual'] : addslashes($_GET['id_manual']);
}
mysql_select_db($database_romarc, $romarc);
$query_adminchapters2 = sprintf("SELECT * FROM manuals WHERE id_manual = %s", $colname_adminchapters2);
$adminchapters2 = mysql_query($query_adminchapters2, $romarc) or die(mysql_error());
$row_adminchapters2 = mysql_fetch_assoc($adminchapters2);
$totalRows_adminchapters2 = mysql_num_rows($adminchapters2);

$queryString_adminchapters = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_adminchapters") == false && 
        stristr($param, "totalRows_adminchapters") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_adminchapters = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_adminchapters = sprintf("&totalRows_adminchapters=%d%s", $totalRows_adminchapters, $queryString_adminchapters);
?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Chapters for Admin</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif;
      font-size: 16px;
      font-weight: bold;
      color: #005A9C;
}
-->
</style>
<link href="../../ASInew.css" rel="stylesheet" type="text/css" />
<link href="../../copyright.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style3 {font-family: Arial, Helvetica, sans-serif}
.style5 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
body {
      margin-left: 0px;
      margin-top: 0px;
      margin-right: 0px;
      margin-bottom: 0px;
}
.style6 {font-size: 18}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
</head>

<body>
<table width="700" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td valign="top"><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
      <tr>
        <td valign="top"><span class="admin">
          <?php
  mxi_includes_start("header.php");
  require(basename("header.php"));
  mxi_includes_end();
?></span></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td valign="top"><?php
  mxi_includes_start("Salutations.php");
  require(basename("Salutations.php"));
  mxi_includes_end();
?></td>
            </tr>
            <tr>
              <td valign="top"><div align="center"><span class="style5"></span>
                <table width="700" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td valign="top"><div align="center">
                      <?php do { ?>
                        <table width="95%" border="0" cellspacing="6" cellpadding="8">
                            <tr>
                                <td><div align="center" class="style1"><?php echo $row_adminchapters2['description_manual']; ?></div></td>
                            </tr>
                            <tr>
                                <td class="style5"><div align="left" class="style2 style6"><?php echo $row_adminchapters['title_book']; ?></div></td>
                            </tr>
                            <tr>
                                <td><div align="left"><?php echo $row_adminchapters['text_book']; ?></div></td>
                            </tr>
                          <tr>
                            <td height="55" valign="top"><div align="left">
                              <?php
// Show IF Conditional region1
if (@$row_adminchapters['revdate_book'] != "") {
?>
                                <table border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td width="232" class="copyright">Revision Date: <?php echo $row_adminchapters['revdate_book']; ?></td>
                                  </tr>
                                </table>
                                <?php }
// endif Conditional region1
?>
                              <?php
// Show IF Conditional region2
if (@$row_adminchapters['supercddate_book'] != "") {
?>
                                <table border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td width="232" class="copyright">Supercides Date: <?php echo $row_adminchapters['supercddate_book']; ?></td>
                                  </tr>
                                </table>
                                <?php }
// endif Conditional region2
?>
                              <?php
// Show IF Conditional region3
if (@$row_adminchapters['original_date_book'] != "") {
?>
                                <table border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td width="232" class="copyright">Original  Date: <?php echo $row_adminchapters['original_date_book']; ?></td>
                                  </tr>
                                </table>
                                <?php }
// endif Conditional region3
?>
                            </div></td>
                          </tr>
                                                  </table>
                        <?php } while ($row_adminchapters = mysql_fetch_assoc($adminchapters)); ?>
                      <table border="0" width="33%" align="center">
                        <tr>
                          <td width="23%" align="center"><?php if ($pageNum_adminchapters > 0) { // Show if not first page ?>
                              <a href="<?php printf("%s?pageNum_adminchapters=%d%s", $currentPage, 0, $queryString_adminchapters); ?>"><img src="First.gif" border=0></a>
                              <?php } // Show if not first page ?>
                          </td>
                          <td width="31%" align="center"><?php if ($pageNum_adminchapters > 0) { // Show if not first page ?>
                              <a href="<?php printf("%s?pageNum_adminchapters=%d%s", $currentPage, max(0, $pageNum_adminchapters - 1), $queryString_adminchapters); ?>"><img src="Previous.gif" border=0></a>
                              <?php } // Show if not first page ?>
                          </td>
                          <td width="23%" align="center"><?php if ($pageNum_adminchapters < $totalPages_adminchapters) { // Show if not last page ?>
                              <a href="<?php printf("%s?pageNum_adminchapters=%d%s", $currentPage, min($totalPages_adminchapters, $pageNum_adminchapters + 1), $queryString_adminchapters); ?>"><img src="Next.gif" border=0></a>
                              <?php } // Show if not last page ?>
                          </td>
                          <td width="23%" align="center"><?php if ($pageNum_adminchapters < $totalPages_adminchapters) { // Show if not last page ?>
                              <a href="<?php printf("%s?pageNum_adminchapters=%d%s", $currentPage, $totalPages_adminchapters, $queryString_adminchapters); ?>"><img src="Last.gif" border=0></a>
                              <?php } // Show if not last page ?>
                          </td>
                        </tr>
                      </table>
                      <br />
</div>                      <div align="center" class="style1">
                        <div align="left" class="title style3"></div>
                      </div></td>
                  </tr>
                </table>
              </div>                <div align="center" class="style1">
                    <div align="left" class="title style3"></div>
                </div></td>
            </tr>
           
            <tr>
              <td height="40" background="../images/BottomBkg.gif"><div align="right">
                <table width="700" border="0" cellspacing="0" cellpadding="6">
                  <tr>
                    <td width="345"><div align="left"><img src="../images/fileprint.png" width="22" height="22" /><span class="admin"> Printer Friendly Page </span></div></td>
                    <td width="114"><div align="right">
                      <input name="button" type="button" onclick="history.go(-1); return false;" value="Go Back" />
                    </div></td>
                    <td width="104">                        <input name="delete" type="submit" id="delete" onclick="MM_goToURL('parent','delete1_chapter.php?id_book=<?php echo $row_adminchapters['id_book']; ?>');return document.MM_returnValue" value="Delete Chapter" />                    </td>
                    <td width="89"><div align="right">
                      <input name="Button" type="button" onclick="MM_goToURL('parent','edit_chapter.php?id_book=<?php echo $row_adminchapters['id_book']; ?>&amp;manual_id_book=<?php echo $row_adminchapters2['id_manual']; ?>');return document.MM_returnValue" value="Edit Chapter" />
                    </div></td>
                  </tr>
                </table>
              </div></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<?php
  mxi_includes_start("footer.php");
  require(basename("footer.php"));
  mxi_includes_end();
?></body>
</html>
<?php
mysql_free_result($adminchapters);

mysql_free_result($adminchapters2);
?>



.......................list page........................................

<?php require_once('../../Connections/romarc.php'); ?>
<?php
// Load the tNG classes
require_once('../../includes/tng/tNG.inc.php');

// Require the MXI classes
require_once ('../../includes/mxi/MXI.php');

// Require the MXI classes
require_once ('../../includes/mxi/MXI.php');

// Make unified connection variable
$conn_romarc = new KT_connection($romarc, $database_romarc);

//Start Restrict Access To Page
$restrict = new tNG_RestrictAccess($conn_romarc, "../../");
//Grand Levels: Level
$restrict->addLevel("3");
$restrict->Execute();
//End Restrict Access To Page

$colname_adminrecord = "-1";
if (isset($_GET['id_manual'])) {
  $colname_adminrecord = (get_magic_quotes_gpc()) ? $_GET['id_manual'] : addslashes($_GET['id_manual']);
}
mysql_select_db($database_romarc, $romarc);
$query_adminrecord = sprintf("SELECT * FROM chapters WHERE manual_id_book = %s ORDER BY title_book ASC", $colname_adminrecord);
$adminrecord = mysql_query($query_adminrecord, $romarc) or die(mysql_error());
$row_adminrecord = mysql_fetch_assoc($adminrecord);
$totalRows_adminrecord = mysql_num_rows($adminrecord);

$colname_adminrecord2 = "-1";
if (isset($_GET['id_manual'])) {
  $colname_adminrecord2 = (get_magic_quotes_gpc()) ? $_GET['id_manual'] : addslashes($_GET['id_manual']);
}
mysql_select_db($database_romarc, $romarc);
$query_adminrecord2 = sprintf("SELECT * FROM manuals WHERE id_manual = %s", $colname_adminrecord2);
$adminrecord2 = mysql_query($query_adminrecord2, $romarc) or die(mysql_error());
$row_adminrecord2 = mysql_fetch_assoc($adminrecord2);
$totalRows_adminrecord2 = mysql_num_rows($adminrecord2);
?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Manual Index</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif;
      font-size: 16px;
      font-weight: bold;
      color: #005A9C;
}
-->
</style>
<link href="../../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" />
<link href="../../ASInew.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style3 {
      font-family: Arial, Helvetica, sans-serif;
      font-weight: bold;
      font-size: 16px;
      color: #666666;
}
-->
</style>
<link href="../../copyright.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
      margin-left: 0px;
      margin-top: 0px;
      margin-right: 0px;
      margin-bottom: 0px;
}
-->
</style></head>

<body>
<table width="700" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><?php
  mxi_includes_start("header.php");
  require(basename("header.php"));
  mxi_includes_end();
?></td>
          </tr>
          <tr>
            <td valign="top"><?php
  mxi_includes_start("Salutations.php");
  require(basename("Salutations.php"));
  mxi_includes_end();
?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top" class="newmenu"></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" align="center" cellpadding="4" cellspacing="0">
            <tr>
              <td width="29%" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="6">
                <tr>
                  <td><?php
  mxi_includes_start("adminMenu.php");
  require(basename("adminMenu.php"));
  mxi_includes_end();
?></td>
                </tr>
              </table></td>
              <td width="71%" align="left" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="8" class="leftBorder">
                  <tr>
                    <td><div align="center"><span class="style1"><?php echo $row_adminrecord2['description_manual']; ?></span></div></td>
                  </tr>
                  <tr>
                    <td><div align="center"><span class="style3">INDEX</span></div></td>
                  </tr>
                  <tr>
                    <td valign="top"><?php do { ?>
                        <table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
                          <tr>
                            <td width="4%" class="newmenu"><img src="../images/smallArrowMenu.gif" width="11" height="11" /></td>
                            <td width="72%" class="newmenu"><a href="admin_chapters.php?id_book=<?php echo $row_adminrecord['id_book']; ?>&amp;id_manual=<?php echo $row_adminrecord2['id_manual']; ?>"><?php echo $row_adminrecord['title_book']; ?></a></td>
                            <td width="24%" class="newmenu"><div align="right">
                                <?php
//Show If User Is Logged In (region1)
$isLoggedIn = new tNG_UserLoggedIn($conn_romarc);
//Grand Levels: Level
$isLoggedIn->addLevel("3");
if ($isLoggedIn->Execute()) {
?>
                                <table width="100" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td><div align="right"><a href="edit_chapter.php?id_book=<?php echo $row_adminrecord['id_book']; ?>&amp;id_manual=<?php echo $row_adminrecord2['id_manual']; ?>">Edit</a></div></td>
                                  </tr>
                                </table>
                              <?php
}
//End Show If User Is Logged In (region1)
?>
                            </div></td>
                          </tr>
                          <tr>
                            <td height="4" colspan="3" class="newmenu"><hr size="1" /></td>
                          </tr>
                        </table>
                      <?php } while ($row_adminrecord = mysql_fetch_assoc($adminrecord)); ?>
                        <table width="100%" border="0" cellspacing="23" cellpadding="9">
                          <tr>
                            <td><div align="right">
                              <input name="button" type="button" onclick="history.go(-1); return false;" value="Go Back" />
</div></td>
                          </tr>
                        </table>
                        <p>&nbsp;</p></td>
                  </tr>
              </table></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td height="40" background="../images/BottomBkg.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<?php
  mxi_includes_start("footer.php");
  require(basename("footer.php"));
  mxi_includes_end();
?></body>
</html>
<?php
mysql_free_result($adminrecord);

mysql_free_result($adminrecord2);
?>


0
romarc
Asked:
romarc
1 Solution
 
RoonaanCommented:
Hi,

I have totally no clue what you are doing. What is the relation between your two tables, and which are the fields that reference each other? Also your code is somewhat complex to read, having no comments in the relevant sections.

Why do you need to look into two tables from a single admin page? Isn't it possible/easier to split the page into two tools, each handling its own table?

-r-
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now