Skip to main content
Participant
March 17, 2014
Question

CS5.5 want to change the number records returned for a repeat region from user input

  • March 17, 2014
  • 1 reply
  • 889 views

Hello,

I am looking to allow the user to set the number of rows returned in a repeat region from the fixed amount set using Server Behaviours to a figure set by the person viewing the page.

I have seen that the code generated uses:

$maxRows_rsVenues = 20;

To start with I thought something simple. Either all records or the preset 20 rows at a time. I presume SESSION variables would be a good way to go so setting a form on the page with a checkbox (checked meaning ALL and unchecked for 20). (It gets me into how the coding works)

Having googled my requirement and read responses on using checkboxes and session variables I had the following theory

At start of page make sure session value exists:

if (!isset($_SESSION))

{

          session_start();

}

$_SESSION['listcount']='20';

In the body before the table created within the repeat region put

    <form id="form1" name="form1" method="post" action="">

      <p id="frmFilter">

        <input name="SeeAll" type="checkbox" id="SeeAll" value="1" />

        <label for="SeeAll">SeeAll</label>

        <input type="submit" name="Set Filter" id="Set Filter" value="Set Filter" />

      </p>

    </form>

    <?php

                    if (isset($_POST['Submit'])) {

                              if ($_POST['SeeAll'] == '1')

                              {

                                  $_SESSION['venuelistcount'] = '999999';

                              } else {

                                  $_SESSION['venuelistcount'] = '20';

                              }

  }

?>

<?php echo "LIST COUNT: ".$_SESSION['venuelistcount']; ?>

The problem is the Session variable never seems to be modified. Can someone explain what I have misunderstood, or perhaps a better option to implement what I want.

Thanks

This topic has been closed for replies.

1 reply

Participating Frequently
March 17, 2014

>    if (isset($_POST['Submit'])) {

Your form has no elements named 'Submit' so it will never get past the first IF statement.

Participant
March 18, 2014

Thanks that was my misunderstanding of the $_POST. I have got it to remember the state now.

I have this code inserted at the begining of the CS5.5 generated code

     <?php require_once('../Connections/dbconn.php'); ?>

     <?php

     if (!isset($_SESSION))

     {

               session_start();

               $_SESSION['listcount']='20';

     }

......

then later replace the rhside of an assignement to use the session variable

...

     $totalRows_rsVenues = mysql_num_rows($rsVenues);

     $maxRows_rsVenues = $_SESSION['venuelistcount'];

     $pageNum_rsVenues = 0;

....

and code in a form to set the session variable

....

    <form id="form1" name="form1" method="post" action="">

      <p id="frmFilter">

        <input name="SeeAll" type="checkbox" id="SeeAll" value="1" />

        <label for="SeeAll">SeeAll</label>

        <input type="submit" name="SetFilter" id="SetFilter" value="Set Filter" />

      </p>

    </form>

    <?php

                    if (isset($_POST['SetFilter'])) {

                              if ($_POST['SeeAll'] == '1')

                              {

                                  $_SESSION['listcount'] = '999999';

                              } else {

                                  $_SESSION['listcount'] = '20';

                              }

                    }

?>

<?php echo "LIST COUNT: ".$_SESSION['listcount']; ?>

But how do I trigger the CS5.5 code to redraw the data with the new values. Or should I not bother with the generated code and do it all in php manually?

Kerry

Participating Frequently
March 18, 2014

But how do I trigger the CS5.5 code to redraw the data with the new values.

What do you mean by 'redraw the data'?

Or should I not bother with the generated code and do it all in php manually?


I think your best bet is to code this by hand. DW's generated code is badly outdated and overly complex. In addition, once you start making changing to the generated code, it breaks the connection to the server behaviors and then DW has a tendency to duplicate the code.