Link to home
Start Free TrialLog in
Avatar of redcable
redcable

asked on

generating a page number based on recordcount

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.

<?php
// 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);
  $check_count=1;
  if ($check_page->RecordCount() > '20') {
    while (!$check_page->EOF) {
      if ($customers->fields['subscription_id'] == $_GET['sID']) {
        break;
      }
      $check_count++;
      $check_page->MoveNext();
    }
// 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.
Avatar of peyox
peyox
Flag of Poland image

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.
Avatar of redcable
redcable

ASKER

any reason why that you can think of mate?
ASKER CERTIFIED SOLUTION
Avatar of ShelfieldCollege
ShelfieldCollege

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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'] != '') ...  

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";
   
}
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.
yep i noticed this, and I was just wasnt paying attention, I gave my self a good wack, thanks for the help mates!!!
Anytime, glad we could help.