generating a page number based on recordcount

Posted on 2005-04-11
Last Modified: 2013-12-12
Hi guys, im trying to generate a page number based on  the db count below but cant seem to get it to work,

Perhaps someone can shed some light or point me in the right direction. ive used my subscription_id number 341 as an example.

my outpout of the script below should be subscription_tracking.php?page='page number here'&sID='341'&action=edit

however i just get, subscription_tracking.php?page=&sID='341'&action=edit

let me walk through what Im doing here.

// lets do a simple query of my subscriptions table
$subscrib_query_raw = "select * from " . TABLE_SUBSCRIPTIONS .  " order by s.subscription_id";

//my goal is to generate a page number because im linking ot a customer record on a diffrent page, and I paginate this page so I only see 20 rows per page.
//because of this if I select a customer record that has a subscription id number of 341, it isnt going ot be on the first page, so i need to generate the page number for the link

// Split Page
// reset page when page is unknown
if ($_GET['pagesubpage'] == '' and $_GET['sID'] != '') {

/count the records  
  $check_page = $db->Execute($subscrib_query_raw);
  if ($check_page->RecordCount() > '20') {
    while (!$check_page->EOF) {
      if ($customers->fields['subscription_id'] == $_GET['sID']) {
// now that ive counted my records, I can generate a page number by doing some math
    $_GET['pagesubpage'] = round((($check_count/'20')+(fmod($check_count,'20') !=0 ? .5 : 0)),0);
// and default to 1 if fails
} else {
    $_GET['pagesubpage'] = 1;

//im generating a simple report of rows based on a query earlier in my code on the same page.
  while (!$customers->EOF) {

    if ($customer_id == $customers->fields['subscription_id'] && substr($action, 0, 3) != 'new') {
        $cInfo = new objectInfo($customers->fields);
//no im going to generate my links so that when i click on this row, it will take me to the subscriptions page where i can view the subscription record.

 if (isset($cInfo) && is_object($cInfo) && ($customers->fields['subscription_id'] == $cInfo->subscription_id)) {                                                                                                                                                                                                                                                            
        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link(FILENAME_SUBSCRIPTION_TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscription_id'] . '&action=edit', 'NONSSL') . '\'">' . "\n";
    } else {                                                                                                                                                                                                                     //zen_href_link(FILENAME_SUBSCRIPTION_TRACK_ADM, . (isset($_GET['page']) ? '&page=' . $_GET['page'] : ''), 'NONSSL'));
      echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link(FILENAME_SUBSCRIPTION_TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscription_id'] . '&action=edit', 'NONSSL') . '\'">' . "\n";

// it looks good, but its not working. anyone out there that can walk me through, and lend a guiding hand.
Question by:redcable
    LVL 6

    Expert Comment

    Look at first IF:

    if ($_GET['pagesubpage'] == '' and $_GET['sID'] != '')

    I think your program is not getting into this IF which results in empty $_GET['pagesubpage'] value.

    Author Comment

    any reason why that you can think of mate?
    LVL 4

    Accepted Solution

    on your url line you're using the variable name of page and in your if statement your using $_GET['pagesubpage'] which doesn't appear to have been set anywhere, unless I'm looking in the wrong place.


    LVL 4

    Expert Comment

    Either change your url to:

    subscription_tracking.php?pagesubpage='page number here'&sID='341'&action=edit
    (note "pagesubpage=" where it first said "page=")

    or change all instances of the word 'pagesubpage' in your script to 'page', i.e:  
    ... if ($_GET['page'] == '' and $_GET['sID'] != '') ...  


    Author Comment

    I dont know are you sure? maybe I need to change something else.

    my link generators are below, and 'page=' isnt a variable

    $_GET['pagesubpage'] is a variable, or do I need to define before I use it in the if statement?

     echo '    <tr "removed some stuff to save room''  . zen_href_link(FILENAME_SUBSCRIPTION_TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscription_id'] . '&action=edit', 'NONSSL') . '\'">' . "\n";
        } else {  
    echo '       <tr "removed some stuff to save room'' . zen_href_link(FILENAME_SUBSCRIPTION_TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscription_id'] . '&action=edit', 'NONSSL') . '\'">' . "\n";
    LVL 4

    Expert Comment

    those two echo lines there look like they're echoing $_GET['pagesubpage'] tp the page= variable (page=' . $_GET['pagesubpage']), try making that pagesubpage=' . $_GET['pagesubpage'] or if you decide to change all instances of $_GET['pagesubpage'] to $_GET['page'] then do it here as well. e.g. page=' . $_GET['pagesubpage']

    It basically depends on whether you want to use the $_GET['page'] variable or $_GET['pagesubpage'] variable, i recommend using $_GET['pagesubpage'] as you only have a couple of lines to change then, anywhere it says page= on your link generators change it to pagesubpage=

    Hope that's helped, if you've still got problems let us know.

    Author Comment

    yep i noticed this, and I was just wasnt paying attention, I gave my self a good wack, thanks for the help mates!!!
    LVL 4

    Expert Comment

    Anytime, glad we could help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now