Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Query spit into pages, script modification help needed.
Old 04-21-2006, 11:07 PM Query spit into pages, script modification help needed.
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
The following script...

PHP Code:
<?php
$numgames 
mysql_query("SELECT * FROM `games` where `gInCategory` = '$cid'");
$numrows mysql_num_rows($numgames);
$ii ceil($numrows $games_per_page2);

$iq     1;
if (
$ii != 1)
    {
        while (
$iq <= $ii)
            {
                if (
$iq != $page)
                    {
                        echo 
"<a href=";
                        echo 
$_SERVER['PHP_SELF'];
                        echo 
"?page=";
                        echo 
$iq;
                        echo 
"&cid=";
                        echo 
$cid;
                        echo 
">";
                    }
                echo 
"[";
                echo 
$iq;
                echo 
"]";
                if (
$iq != $page)
                    {
                        echo 
"</a>";
                    }
                echo 
"&nbsp;";
                
$iq++;
            }
    }
   
?>
...prints something like [1] [2] [3] [4] [5] [6] [7], which would go on for all pages, i wish to only print next and previous 4 plus 1st and last if possible.

e.g.

[<<<] [5] [6] [7] [8] [10] [11] [12] [13] [>>>]

Any helpful people able to help with this?
__________________
Wont :P

Please login or register to view this content. Registration is FREE
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
 
Register now for full access!
Old 04-22-2006, 08:55 AM Re: Query spit into pages, script modification help needed.
Experienced Talker

Posts: 40
Location: Denmark
Trades: 0
Hi,

$num_rows should be changed so it gets the number of rows from database (like your own code)..

I havnt tested it very much, but if you create a new php-file and run that, you should be able to see how it works, before changing your own stuff.

PHP Code:
<?php
# Settings
$num_rows 170;        # How many rows in total
$rows_pr_page 10;     # How many rows per page?
$show_pages 6;        # How many page-links we want? (excluding current page)

$total_pages ceil($num_rows/$rows_pr_page);   # Calc number of pages
$current_page intval(@$_GET['page']);         # Get currnet page

# sanitize $current_page
if( $current_page $current_page 1;
if( 
$current_page $total_pages $current_page $total_pages;

# Calc start page
$start_at_page $current_page floor($show_pages/2);
if( 
$start_at_page $start_at_page 1;

# Calc end page
$end_at_page $current_page ceil($show_pages/2);
if( 
$end_at_page $total_pages $end_at_page $total_pages;

# Show "prev" link
if( $current_page $start_at_page )
    print 
page_link("[<<<]"$current_page 1) . " ";
else
    print 
page_link("[<<<]") . " ";

# Show page-links
for($page $start_at_page$page <= $end_at_page$page++) {
    
$curpagelink = ($page == $current_page);
    
    
$link "[$page]";
    
    if( 
$curpagelink )
        print 
page_link("<b>$link</b>") . " ";
    else
        print 
page_link($link$page) . " ";
}       

# Show "next" link
if( $current_page $end_at_page )
    print 
page_link("[>>>]"$current_page 1) . " ";
else
    print 
page_link("[>>>]") . " ";

# Helper function to creat ethe links
function page_link($text$page=null) {
    if( 
$page 
        return 
"<a href=\"?page=$page\">$text</a>";
    else
        return 
$text;
}       
?>
dennismp is offline
Reply With Quote
View Public Profile Visit dennismp's homepage!
 
Old 04-22-2006, 09:26 AM Re: Query spit into pages, script modification help needed.
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
Works. I have to change link to have &cid=<?php echo $cid ?> at the end previously done by echo "&cid=";
echo $cid;

I shal let you know after that if it works and post finished code for anybody needing it
__________________
Wont :P

Please login or register to view this content. Registration is FREE
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Old 04-22-2006, 09:31 AM Re: Query spit into pages, script modification help needed.
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
PHP Code:
<table width="100%"  border="0" cellpadding="0" cellspacing="0" class="greyBox"><tr><td><table width="100%"  border="0" cellspacing="0" cellpadding="0"> 
<tr><td><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="categHead"> 
<tr>
  <td>&nbsp; Select a Game </td> 
</tr></table></td></tr><tr><td>
<table width="100%" height="108"  border="0" cellpadding="0" cellspacing="6"> 
 <tr>  <td width="50%" height="96" valign="top" bgcolor="#F7F8FD"><table width="100%" height="72" border="0" cellpadding="0" cellspacing="3" class="game">
   <tbody>
     <tr align="left" valign="top">
       <?php
       
include ("config.php");
if (!(
$page)){
     
$page 1;}
     
$offset = ($page 1) * $games_per_page2;
        
$qstr "SELECT DISTINCT g.gId AS game_id, g.gName AS game_name, g.gThumb AS game_thumb, g.gDescription AS game_description, c.cName AS category_name FROM games g LEFT JOIN categories c ON c.cId=g.gInCategory WHERE g.gInCategory = $cid ORDER BY gName ASC LIMIT $offset$games_per_page2"
$count 0;
$games mysql_query($qstr);
while (list (
$gameid$gamename$thumb$description$catname) = mysql_fetch_row($games)){ 
?>
       <?php
if ($count == 2) {
?>
     <tr align="left" valign="top">
       <?php
}
?>
       <td align="center"><span class="normalText">
         <?php
if ($seo_support == 1){ echo "<a href=\"play-$gameid.html\">"; } else {
echo 
"<a href=\"ply.php?id=$gameid\">";}
?>
         <img src="../images/upload/<?php echo"$thumb"?>" alt="<?php echo"$gamename"?>" border="0" height="60" width="60"></span></td>
       <td class="normalText" width="33%"> <b>
         <?php
if ($seo_support == 1){ echo "<a href=\"play-$gameid.html\">"; } else {
echo 
"<a href=\"ply.php?id=$gameid\">";}
?>
         <?php echo"$gamename"?> </b><br>
         <?php echo"$description"?><br>
         <?php
if ($seo_support == 1){ echo "<a href=\"play-$gameid.html\" class=gameLink>"; } else {
echo 
"<a href=\"ply.php?id=$gameid\" class=gameLink>";}
?>
         <b>Play now!</b> </td>
       <?php
if ($count == 1) {
?>
     </tr>
     <?php
}
?>
     <?php
if ($count == 2) {
$count $count -1;
}elseif (
$count == 0){
$count $count +1;
}else {
$count $count +1;
}
?></tbody>
 </table> 
<?php
# Settings
$numgames mysql_query("SELECT * FROM `games` where `gInCategory` = '$cid'");
$num_rows mysql_num_rows($numgames);
$rows_pr_page $games_per_page2;     # How many rows per page?
$show_pages 8;        # How many page-links we want? (excluding current page)

$total_pages ceil($num_rows/$rows_pr_page);   # Calc number of pages
$current_page intval(@$_GET['page']);         # Get currnet page

# sanitize $current_page
if( $current_page $current_page 1;
if( 
$current_page $total_pages $current_page $total_pages;

# Calc start page
$start_at_page $current_page floor($show_pages/2);
if( 
$start_at_page $start_at_page 1;

# Calc end page
$end_at_page $current_page ceil($show_pages/2);
if( 
$end_at_page $total_pages $end_at_page $total_pages;

# Show "prev" link
if( $current_page $start_at_page )
    print 
page_link("[<<<]"$current_page 1) . " ";
else
    print 
page_link("[<<<]") . " ";

# Show page-links
for($page $start_at_page$page <= $end_at_page$page++) {
    
$curpagelink = ($page == $current_page);
    
    
$link "[$page]";
    
    if( 
$curpagelink )
        print 
page_link("<b>$link</b>") . " ";
    else
        print 
page_link($link$page) . " ";
}       

# Show "next" link
if( $current_page $end_at_page )
    print 
page_link("[>>>]"$current_page 1) . " ";
else
    print 
page_link("[>>>]") . " ";

# Helper function to creat ethe links
function page_link($text$page=null) {
    if( 
$page 
        return 
"<a href=\"?page=$page&cid=$cid\">$text</a>";
    else
        return 
$text;
}       
?>
here is code...

is is not adding cid=$cid

http://www.backthebulls.com/test.php?cid=1
__________________
Wont :P

Please login or register to view this content. Registration is FREE
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Old 04-22-2006, 05:00 PM Re: Query spit into pages, script modification help needed.
Experienced Talker

Posts: 40
Location: Denmark
Trades: 0
you can change
PHP Code:
function page_link($text$page=null) {
    if( 
$page 
        return 
"<a href=\"?page=$page&cid=$cid\">$text</a>";
    else
        return 
$text;

into

PHP Code:
function page_link($text$page=null) {
    global 
$cid;
    if( 
$page 
        return 
"<a href=\"?page=$page&cid=$cid\">$text</a>";
    else
        return 
$text;

or you can make an additional parameter to the function and pass $cid to it each time you call it.
dennismp is offline
Reply With Quote
View Public Profile Visit dennismp's homepage!
 
Old 04-22-2006, 07:21 PM Re: Query spit into pages, script modification help needed.
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
thanks, problem solved.
__________________
Wont :P

Please login or register to view this content. Registration is FREE
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Reply     « Reply to Query spit into pages, script modification help needed.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25899 seconds with 12 queries