/    Sign up×
Community /Pin to ProfileBookmark

seperating a statment of different pages

Hi can any see why when i click next nothing happens

[code=php]

function make_user_page_nums($total_results, $print_query, $page_name, $results_per_page, $page, $max_pages_to_show) {

echo “Pages: “;

/* PREV LINK: print a Prev link, if the page number is not 1 */
if($page != 1) {
$pageprev = $page – 1;
echo “<a href=””.$page_name.$print_query.”page=”.$pageprev.””>&lt;Prev</a> “;
}

/* get the total number of pages that are needed */

$showpages = round($max_pages_to_show/2);
$numofpages = $total_results/$results_per_page;

if ($numofpages > $showpages ) {
$startpage = $page – $showpages ;
} else {
$startpage = 0;
}

if ($startpage < 0){
$startpage = 0;
}

if ($numofpages > $showpages ) {
$endpage = $page + $showpages;
} else {
$endpage = $showpages;
}

if ($endpage > $numofpages){
$endpage = $numofpages;
}

/* loop through the page numbers and print them out */
for($i = $startpage; $i < $endpage; $i++) {

/* if the page number in the loop is not the same as the page were on, make it a link */
$real_page = $i + 1;
if ($real_page!=$page){
echo ” <a href=””.$page_name.$print_query.”page=”.$real_page.””>”.$real_page.”</a> “;

/* otherwise, if the loop page number is the same as the page were on, do not make it a link, but rather just print it out */
} else {
echo “<b>”.$real_page.”</b>”;
}
}

/* NEXT LINK -If the totalrows – $results_per_page * $page is > 0 (meaning there is a remainder), print the Next button. */
if(($total_results-($results_per_page*$page)) > 0){
$pagenext = $page + 1;
echo ” <a href=””.$page_name.$print_query.”page=”.$pagenext.””>Next &gt;</a> “;
}

}
?>
[/code]

just whenever i click on anything it dont work?

Thanks Adam

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@k0r54authorSep 11.2004 — The coding directly before the one above is

[code=php]
<?php

/* per page limit - this can be included in a seperate file, as long as you
are sure to include that fle on the page you want the numbering on - otherwise
its fine to just code it here - for this example, we're using 16 items per page */
$user_view_limit = "16";


/* set this variable to whatever the max number of page numbers you wish to be
displayed at any given time */
$max_pages_to_show = 5;

/* if there is no page # passed, assign $page the value of 1 */
if ((empty($page)) || ($page <= 0)){
$page = 1;
}

/* this code just figures out the limit for the sql statement that actually
gets that page's item data */
$limitvalue = $page*$user_view_limit-($user_view_limit);


/* the query to get actual results - your query would go here, but be sure to
include the LIMIT $limitvalue, $user_view_limit part at the end.
Our example is pulling articles from the "articles" table that have the category ID of 2 */
$conn = mysql_connect("localhost","apccomputest","sepultura");

mysql_select_db("apccomputest",$conn) or die(mysql_error());

$sql = "select title from pages LIMIT $limitvalue, $user_view_limit";

/* the query to get the total number without the limit */
$sqlcount = "select count(*) from pages ";

/* this is used by the function in case you need to pass other stuff in your
query string. If you're not passing anything else, this should be set to just "?"
as is shown in this example -
To pass more variables through the query string, you would just change it to
something like: $print_query ="?cat_id=$cat_id&"; */
$print_query ="?";


/* get the total number data and find out what the grand total is */
$sql_countresult = mysql_query($sqlcount,$conn);
list($totalrows) = mysql_fetch_row($sql_countresult);

/* get the actual item data and print it out on the page */
if ($get_items = mysql_query($sql,$conn)) {
$num_items = mysql_num_rows($get_items);

/* see if we actually have any matches in the DB */
if ($num_items > 0) {

/* if theres more than one page needed, print out the page #s
In this example, products.php is the page that the link will be printed out with.
To use a different page, simply change this value in your function call */
if ($user_view_limit < $totalrows) {
make_user_page_nums($totalrows, $print_query, $_SERVER['PHP_SELF'], $user_view_limit, $page, $max_pages_to_show);
}


/* print out the actual item details - you would cange this code to
make it print out the fields and data the way you want it to appear
on the page */
while (list($foo) = mysql_fetch_row($get_items) ) {
echo "<li>";
echo $foo;

}

/* if there are no matches, print our an error */
} else {
echo "No items listed";
}


/* if the query failed, lets see if mysql returns an error */
} else {
echo "An error has occurred: <br>";
echo mysql_error();
}
[/code]
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...