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?

Member Avatar for diafol

SHow your code Dave, don't leave us guessing...

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>
Member Avatar for diafol

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?

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.

Does the $colname_Recordset1 value come here?

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

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

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

does the $colname_Recordset1 value print with the above line?

Member Avatar for cuonic

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

for pagination refer to the following link....Click here

Member Avatar for diafol

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...

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.

Member Avatar for diafol

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

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

Member Avatar for cuonic

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...

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.