MySQL Result with Pagination

Does anyone know how to display results from the database and display in a single column with pagination. I did some tinkering around before and can not seem to get exactly what I am looking for. To clarify, here's what I am trying to accomplish:

I have a database table called Goals

In this table I have a few fields - goal_id, goal_name, goal_start, goal_expected_accomplish, goal_end, goal_accomplish_yn, user_id

I want to display results in a single column view - much like that of the Groups (when viewing My Groups) list (but of course without the image), Including the pagination.

 

Any assistance on this would be greatly appreciated, and as always, Thanks in advance.

caredesign.net
Quote · 26 Nov 2013

Well, I have been playing with this task all night. I managed to get a few things working, but not working completely. So far, I am able to get the list of table items to display, but when setting perPage = 1, I am still getting all items in the listing, not just 1. I do have the pagination at the bottom, and it seems like it is going between the pages, but my output list is acting up for some reason. Below is my code for the page block.

 

function getBlockCode_ProgressNotes()
    {
        if (!$this->aDataEntry)
            return '';

        $iPage = (int)$_GET['page'];
        if( $iPage < 1)
            $iPage = 1;
        $aProfiles = mysql_query("SELECT * FROM `cf_clients_progress_notes` WHERE `client_id` = '" . $this->aDataEntry['id'] . "' ORDER BY `progress_note_id` DESC ");
        $iNum = mysql_num_rows($aProfiles);
        if (!$iNum || !$aProfiles)
            return MsgBox(_t("_Empty"));
       
        $sMainContent = '';
       
        while ($row = mysql_fetch_array($aProfiles)) {
        $sMainContent .= $row['date'] . '<br>';
        }

        $ret .= $sMainContent;
        $ret .= '<div class="clear_both"></div>';

        $oPaginate = new BxDolPaginate(array(
            'page_url' => 'javascript:void(0);',
            'count' => $iNum,
            'per_page' => '1',
            'page' => $iPage,
            'on_change_page' => 'return !loadDynamicBlock({id}, \'' . bx_append_url_params(BX_DOL_URL_ROOT . $this->_oMain->_oConfig->getBaseUri() . "view/" . $this->aDataEntry[$this->_oDb->_sFieldUri], 'page={page}&per_page={per_page}') . '\');',
        ));
        $sAjaxPaginate = $oPaginate->getPaginate();
        return array($ret, array(), $sAjaxPaginate);
    }

 

you can test here: http://mytherapysession.org/m/clients/view/Test-Client-1

caredesign.net
Quote · 27 Nov 2013

Access denied

Geeks, making the world a better place
Quote · 27 Nov 2013

sorry about that-  forgot i didnt have it for guests to view.

 

Well, I managed to fix the issue where it was showing all items in the list. I had a . in there where I did not need one. Now, when going to a different page, it shows the same item from page 1.

caredesign.net
Quote · 27 Nov 2013

Increase the per page number and see what shows up; might help to indicate something.

Geeks, making the world a better place
Quote · 27 Nov 2013

I'm getting lots of errors when I click around... :)

P.

Peer L. Plaut Executive Director, Single Booklovers Connecting Bookworms Since 1970
Quote · 27 Nov 2013

OK, I made a few changes and still stuck at a brixk wall. CHanged the perPage to 2 (there are 3 entries in the database) and here is my current coding:

 

function getBlockCode_ProgressNotes()
    {
        if (!$this->aDataEntry)
            return '';

        $iPage = (int)$_GET['page'];
        if( $iPage < 1)
            $iPage = 1;
           
        $iPerPage = '2';
        $sLimitFrom = $iPage - 1;
        $sqlLimit = "LIMIT " . $sLimitFrom . ", " . $iPerPage;
        $aProfiles2 = mysql_query("SELECT * FROM `cf_clients_progress_notes` WHERE `client_id` = '1' {$sSqlLimit}");        
        $aProfiles = mysql_query("SELECT * FROM `cf_clients_progress_notes` WHERE `client_id` = '1'");
        $iNum = mysql_num_rows($aProfiles);
        if (!$iNum || !$aProfiles2)
            return MsgBox(_t("_Empty"));
       
        while ($row = mysql_fetch_array($aProfiles2)) {
        $sMainContent = $row['date'] . "<br>";
        }
        $ret .= $sMainContent;
       
        $oPaginate = new BxDolPaginate(array(
            'page_url' => 'javascript:void(0);',
            'count' => $iNum,
            'per_page' => $iPerPage,
            'page' => $iPage,
            'on_change_page' => 'return !loadDynamicBlock({id}, \'' . bx_append_url_params(BX_DOL_URL_ROOT . $this->_oMain->_oConfig->getBaseUri() . "view/" . $this->aDataEntry['uri'], 'page={page}&per_page={per_page}') . '\');',
        ));
        $sAjaxPaginate = $oPaginate->getPaginate();
        return array($sMainContent, array(), $sAjaxPaginate);
    }

caredesign.net
Quote · 28 Nov 2013

Well - I couldnt get it to work using Dolphins base pagination, but I did get it to work using a long method. If anyone happens to figure out how to do it dolphin's way, that would be great. But for now, I am posting what I have in a PHP block.

 

 $client_id = $this->aDataEntry['id'];
        $client_uri = $this->aDataEntry['uri'];
       if (!(isset($pagenum))) {   
         $pagenum = 1;
         }

$sql= mysql_query("SELECT `date` FROM `cf_clients_progress_notes` WHERE `client_id` = '1'");    

$nr = mysql_num_rows($sql); // Get total of Num rows from the database query
if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
    //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated)
} else { // If the pn URL variable is not present force it to be value of page number 1
    $pn = 1;
}
//This is where we set how many database items to show on each page
$itemsPerPage = 2;
// Get the value of the last page in the pagination result set
$lastPage = ceil($nr / $itemsPerPage);
// Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage
if ($pn < 1) { // If it is less than 1
    $pn = 1; // force if to be 1
} else if ($pn > $lastPage) { // if it is greater than $lastpage
    $pn = $lastPage; // force it to be $lastpage's value
}
// This creates the numbers to click in between the next and back buttons
// This section is explained well in the video that accompanies this script
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $add1 . '\'); return false;" href="javascript:void(0);">' . $add1 . '</a> &nbsp;';
} else if ($pn == $lastPage) {
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $sub1 . '\'); return false;" href="javascript:void(0);">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $sub2 . '\'); return false;" href="javascript:void(0);">' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $sub1 . '\'); return false;" href="javascript:void(0);">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $add1 . '\'); return false;" href="javascript:void(0);">' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $add2 . '\'); return false;" href="javascript:void(0);">' . $add2 . '</a> &nbsp;';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $sub1 . '\'); return false;" href="javascript:void(0);">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $add1 . '\'); return false;" href="javascript:void(0);">' . $add1 . '</a> &nbsp;';
}
// This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
// Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
// $sql2 is what we will use to fuel our while loop statement below

 
 $sql2= mysql_query("SELECT `date` FROM `cf_clients_progress_notes` WHERE `client_id` = '1' $limit");    
// We are going to use the "$row" method for this query. This is just my preference.
 $paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1"){
    // This shows the user what page they are on, and the total number of pages
//    $paginationDisplay .= 'Page ' . $pn . ' of ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';
    // If we are not on page 1 we can place the Back button
    if ($pn > 3) {
        $first = 1;
        $paginationDisplay .=  '<a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $first . '\'); return false;" href="javascript:void(0);" title="First page">
<i class="sys-icon step-backward"> </i>';
    }
    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '<a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $previous . '\'); return false;" href="javascript:void(0);" title="Previous page">
<i class="sys-icon backward"> </i>';
    }
  
  
    // Lay in the clickable numbers display here between the Back and Next links
    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
    // If we are not on the very last page we can place the Next button
    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '<a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $nextPage . '\'); return false;" href="javascript:void(0);"
<i class="sys-icon forward"> </i></a>';
    }
    if ($pn != $lastPage && $pn != $first) {
      
        $paginationDisplay .=  '<a onclick="javascript:return !loadDynamicBlock(392, \'http://mytherapysession.org/m/clients/view/Test-Client-1?pn=' . $lastPage . '\'); return false;" href="javascript:void(0);"  title="Last page">
<i class="sys-icon step-forward"> </i></a>';
    }
}
echo "<div class=\"boxContent\">";
echo "<div class=\"dbContent bx-def-bc-margin\">";
// Build the Output Section Here
$outputList = '';
 while ($row = mysql_fetch_array($sql2)) {
$date = $row["date"];
echo $date . "</br>";
    // Add 1 to the row count
    $row_count++;
    }
echo "</div>";
echo "</div>";
echo "<div class='paginate bx-def-padding-right bx-def-padding-left'><div class='per_page_section'><div class='info'>$nr Progress Notes for this Client</div></div><div class='pages_section'><div class='active_page'>$paginationDisplay</div></div></div>
";

caredesign.net
Quote · 28 Nov 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.