Jump to content

keeping note of where you are


PC Nerd

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
Link to comment
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.
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.