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=edi t
however i just get, subscription_tracking.php? page=&sID= '341'&acti on=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_que ry_raw);
$check_count=1;
if ($check_page->RecordCount( ) > '20') {
while (!$check_page->EOF) {
if ($customers->fields['subsc ription_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($ch eck_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['subscr iption_id' ] && substr($action, 0, 3) != 'new') {
$cInfo = new objectInfo($customers->fie lds);
}
//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['subsc ription_id '] == $cInfo->subscription_id)) {
echo ' <tr id="defaultSelected" class="dataTableRowSelecte d" onmouseover="rowOverEffect (this)" onmouseout="rowOutEffect(t his)" onclick="document.location .href=\'' . zen_href_link(FILENAME_SUB SCRIPTION_ TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscr iption_id' ] . '&action=edit', 'NONSSL') . '\'">' . "\n";
} else { //zen_href_link(FILENAME_S UBSCRIPTIO N_TRACK_AD M, . (isset($_GET['page']) ? '&page=' . $_GET['page'] : ''), 'NONSSL'));
echo ' <tr class="dataTableRow" onmouseover="rowOverEffect (this)" onmouseout="rowOutEffect(t his)" onclick="document.location .href=\'' . zen_href_link(FILENAME_SUB SCRIPTION_ TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscr iption_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.
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?
however i just get, subscription_tracking.php?
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_que
$check_count=1;
if ($check_page->RecordCount(
while (!$check_page->EOF) {
if ($customers->fields['subsc
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')
// 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['subscr
$cInfo = new objectInfo($customers->fie
}
//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['subsc
echo ' <tr id="defaultSelected" class="dataTableRowSelecte
} else { //zen_href_link(FILENAME_S
echo ' <tr class="dataTableRow" onmouseover="rowOverEffect
}
?>
// it looks good, but its not working. anyone out there that can walk me through, and lend a guiding hand.
ASKER
any reason why that you can think of mate?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Either change your url to:
subscription_tracking.php? pagesubpag e='page number here'&sID='341'&action=edi t
(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'] != '') ...
subscription_tracking.php?
(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'] != '') ...
ASKER
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_SUB SCRIPTION_ TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscr iption_id' ] . '&action=edit', 'NONSSL') . '\'">' . "\n";
} else {
echo ' <tr "removed some stuff to save room'' . zen_href_link(FILENAME_SUB SCRIPTION_ TRACK_ADM, 'page=' . $_GET['pagesubpage'] . '&sID=' . $customers->fields['subscr iption_id' ] . '&action=edit', 'NONSSL') . '\'">' . "\n";
}
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_SUB
} else {
echo ' <tr "removed some stuff to save room'' . zen_href_link(FILENAME_SUB
}
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.
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.
ASKER
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.
if ($_GET['pagesubpage'] == '' and $_GET['sID'] != '')
I think your program is not getting into this IF which results in empty $_GET['pagesubpage'] value.