0

Hi. I use DW cs4 for pagination in order to let users page through a record set. It always worked until I use a $variable in a SELECT statement. If I hard code something, it works, variables don't.
Any solutions to this?

5
Contributors
15
Replies
16
Views
6 Years
Discussion Span
Last Post by phpDave
Featured Replies
  • Dreamweaver is very messy when it comes to PHP coding. I recommend you learn how to do all this by hand... It is much faster and easier to debug if an error crops up. With the dreamweaver code, you need to have a more advanced understanding of how the entire … Read More

  • for pagination refer to the following link....Click [URL="http://www.daniweb.com/web-development/php/code/351142"]here[/URL] Read More

  • 1
    diafol 3,720   6 Years Ago

    DW code is mingin'. I'd start again if I were you. DW doesn't seem to want to clean/sanitize input either. V. dangerous. I was wondering why I was seeing loads of s/printf wrt mysql. It's blinkin DW! Yuk... Read More

0

OK. I ve been trying a few things, here is the latest:

<?php
$currentPage = $_SERVER["PHP_SELF"];
//
$maxRows_Recordset1 = 1;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "-1";
if (isset($_SERVER['QUERY_STRING'])) {
  echo $colname_Recordset1 = $_SERVER['QUERY_STRING'];
}
mysql_select_db($database_connAdmin, $connAdmin);
$query_Recordset1 = sprintf("SELECT * FROM title WHERE catagory = '$colname_Recordset1'", GetSQLValueString($colname_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $connAdmin) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false && 
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>

This is what is below the DOCTYPE:

<table width="70%" border="1">
  <?php do { ?>
    <tr>
      <td>&nbsp;</td>
      <td><?php echo $row_Recordset1['name']; ?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<table border="0">
  <tr>
    <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="images/First.gif" /></a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="images/Previous.gif" /></a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="images/Next.gif" /></a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="images/Last.gif" /></a>
        <?php } // Show if not last page ?></td>
  </tr>
</table>
0

Blinkin heck, you certainly like your s/printf's!

So which line number are we supposed to be looking at? Which variable causes the problem?

0

Here seems to be problem. $colname_Recordset1 is the var.

$query_Recordset1 = sprintf("SELECT * FROM title WHERE catagory = '$colname_Recordset1'",

Here is what can work: Peter being in the catagory col.

$query_Recordset1 = sprintf("SELECT * FROM title WHERE catagory = 'Peter'",

Note: the first record set is show but click on next and nothing displayed.

0

If I understand your question right, the $colname_Recordset1 carries value from a link from another page.

0
echo $colname_Recordset1 = $_SERVER['QUERY_STRING'];

does the $colname_Recordset1 value print with the above line?

1

Dreamweaver is very messy when it comes to PHP coding. I recommend you learn how to do all this by hand... It is much faster and easier to debug if an error crops up. With the dreamweaver code, you need to have a more advanced understanding of how the entire site works

1

DW code is mingin'. I'd start again if I were you. DW doesn't seem to want to clean/sanitize input either. V. dangerous. I was wondering why I was seeing loads of s/printf wrt mysql. It's blinkin DW! Yuk...

0

Karthic- Yes, the value is going through. Visable in an echo statement.
Cuonic-I agree. Pagination is new to me. I'll start to work on it by hand.
Ardav-I do user DW to code some but also do a lot of hand coding.

0

Ok, pagination - there are about a million threads on Daniweb dealing with this. I've contributed to a few hundred myself!

0

Ok, I'll have to study pagination more and use DW less.
Thanks for responses.

0

phpDave: You should really learn to do all the mysql queries yourself too, Dreamweaver doesn't sanitize inputs correctly and uses plenty of useless code for nothing...

0

I agree. I actually do a lot of coding on my own but I did not realize how bad DW writes php. Thanks for info.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.