Jump to content

Archived

This topic is now archived and is closed to further replies.

PC Nerd

keeping note of where you are

Recommended Posts

i want to create a page, which loops on itself, eg page.php

the page sources from a very large database, so i want to display 20 entrys per page, and display them in order of points, then alphabetically.  i dont want to display enrtys multiple time.

i havent written any PHP, but im thinking of how to approach this problem.

All help  is much appreciated,

Pc Nerd

Share this post


Link to post
Share on other sites
Now I think that most of this can be solved with your approach towards searching the data base. To display results by a specific order you can use something like this:

[code=php:0]$query = "SELECT search1, search2 FROM your_table ORDER BY your_order limit 0, 20";[/code]

I wrote this quickly so you might want to search the manual for the proper syntax. Hopefully this will help alittle.

Share this post


Link to post
Share on other sites
ok. then how would i display enrties 20 - 40

and there fore would i have to create a script that would re-rank the entrys.  (im writing a game, so the database is continually minipulated)

if so, how would i write it so that it runns every, 20 minute (or like), without me having to continually manually run the script.  i want the site to be as sent maintaing as possible

thanks for your help with that query,

PC Nerd

Share this post


Link to post
Share on other sites
this tutorial should help you with what you are wanting [url=http://www.phpfreaks.com/tutorials/43/1.php]http://www.phpfreaks.com/tutorials/43/1.php[/url] at least as far as the pagination end.

Share this post


Link to post
Share on other sites

<?php

    @mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER");
    @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");

    $limit          = 20;               
    $query_count    = "SELECT count(*) FROM table";   
    $result_count  = mysql_query($query_count);   
    $totalrows      = mysql_num_rows($result_count); 

    if(empty($page)){
        $page = 1;
    }
       

    $limitvalue = $page * $limit - ($limit); 
    $query  = "SELECT search1,search2 FROM table_name LIMIT $limitvalue, $limit";       
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

   

    echo("<table>");
   
    while($row = mysql_fetch_array($result)){
 
echo $row['what_ever'];
    }

    echo("</table>");

    if($page != 1){ 
        $pageprev = $page--;
       
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); 
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit; 
   
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); 
    }else{
        echo("NEXT".$limit); 
    }
   
    mysql_free_result($result);

?>

There you go good luck.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.