Current location: Hot Scripts Forums » Programming Languages » PHP » Simple problem with my topsites script... plz help...


Simple problem with my topsites script... plz help...

Reply
  #1 (permalink)  
Old 01-05-06, 01:18 PM
latheesan latheesan is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Simple problem with my topsites script... plz help...

Hello,

I created this topsites index page to show list of "topsites" in the db and also show pagination.

What i wanted to show on my first column was the rank, second column is id and third column the banner (for e.g).

The so called "rank" is given by the total incoming hits. The topsites are displayed by incoming hits, decending. That means, the first row that gets displayed has the heightst rank, which is "1". And the second row that gets displayed has the second height rank, which is "2" and so forth.

So, my code is looking something like this:

PHP Code:

<?php

define
('SCRIPT_PATH'$_SERVER['DOCUMENT_ROOT']);
include(
SCRIPT_PATH.'/php-api/txt-db-api.php');
$db = new Database("topsites");

$rowsPerPage 2;
$pageNum 1;
if(isset(
$_GET['page']))
{
        
$pageNum $_GET['page'];
}
if(
$pageNum>1){
$i=$pageNum*$rowsPerPage;
}else{
$i=0;
}  
$offset = ($pageNum 1) * $rowsPerPage;
$result $db->executeQuery("SELECT * FROM main WHERE active = 'yes' ORDER BY hits
DESC LIMIT 
$offset$rowsPerPage");
if(
$result->getRowCount() > 0)
{
        while(
$result->next())
        {
                
$i++;
                
$data $result->getCurrentValuesAsHash();
                
$id $data['id'];
                
$banner $data['banner'];
                echo 
"$i - $id - $banner "// sample output
        
}
}

$result $db->executeQuery("SELECT COUNT(*) AS numrows FROM main");
if(
$result->getRowCount() > 0)
{
        while(
$result->next())
        {
                
$data $result->getCurrentValuesAsHash();
                
$numrows $data['numrows'];
                
$maxPage ceil($numrows/$rowsPerPage);
        }
}

$nav '';
$self "/?L=TopSites.index";
for(
$page 1$page <= $maxPage$page++)
{
if (
$page == $pageNum)
{
$nav .= $page ";
}
else
{
$nav .= " <a class=\"pagenum\" href=\"$self&page=$page\">$page</a> ";
}
}
?>
<br>
<?=$nav;?>
now the above code works, it displays the first two records. the first record is rank 1 and second is rank 2. on the bottom of the page, it displays the navigation which is dynamically created for the total number of pages.

so i clicked on the second page, and it showed me the thrid banner, but rank was "5" and the fourth banner, but the rank was "6"

which is completely wrong

when its suppose to show, third banner is rank 3 and fourth banner is rank 4

as u can see, the value of the $i should be continueing from where it left off from the page 1 to page 2 to page 3 etc... but it isnt

help plz...
Reply With Quote
  #2 (permalink)  
Old 01-05-06, 01:27 PM
latheesan latheesan is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
lolx,

i fixed it

i had to change the $ incrementing part like this

PHP Code:

if($pageNum>1){

        
$i=$pageNum;
        }else{
        
$i=0;
        } 
yeyyy it works
Reply With Quote
  #3 (permalink)  
Old 01-06-06, 08:34 AM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Nice1

To simplify the IF statement, you could easily assign a value to $i by using this statement
PHP Code:

$i = (($pageNum 1)? $pageNum0); 

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
i need a simple login and registration php script plz lunarboi Script Requests 3 01-03-06 12:04 AM
PHP script problem (please help) osmanmumtaz PHP 0 05-24-05 07:29 AM
Simple Banner Script n00bie Script Requests 0 03-07-05 11:29 PM
Creating Website Script Problem Dainbramaged05 PHP 4 06-30-04 12:29 PM


All times are GMT -5. The time now is 06:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.