Jump to content


Photo

keeping note of where you are


  • Please log in to reply
4 replies to this topic

#1 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 16 July 2006 - 12:26 PM

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

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 July 2006 - 12:37 PM

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:

$query = "SELECT search1, search2 FROM your_table ORDER BY your_order limit 0, 20";

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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 16 July 2006 - 12:41 PM

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

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 July 2006 - 01:01 PM

this tutorial should help you with what you are wanting http://www.phpfreaks...orials/43/1.php at least as far as the pagination end.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 July 2006 - 01:08 PM


<?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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users