Unstoppable Domains โ€” Expired Auctions

Php help.

SpaceshipSpaceship
Watch

J_Ronaldo_19

Account Closed
Impact
4
does anybody know how to make a script to show 10 results per page :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
10 results of what? A database query?
 
0
•••
Its simple Ronaldo
use $_GET['page']
and then divide pages based on the number of rows fetched divided by 10
use it as hyperlink and there you go.!!
 
0
•••
that seems harder than it looks.

I mean like google do for there search engine
 
0
•••
Basically you need the LIMIT clause if you are pulling results from a mySQL DB.
For example to display page 1 you need a query like
PHP:
select record from table order by whatever LIMIT 0,10
this will return the first 10 records with the sort order you specify

then for page 2
PHP:
select record from table order by whatever LIMIT 10,10
you have the next 10 records and so on
 
0
•••
I need it automated because this is a search engine where people submit there sites so...
 
0
•••
select record from table where ID>'$_GET[startid] LIMIT 10;

then make the links page.php?startid=0 etc
 
0
•••
Your all confusing me what should I do?
 
0
•••
0
•••
Im not that new to PHP just... "Pagination" I'll look at this tommorrow :)

EDIT: What don't I need in this code?

PHP:
<?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          = 25;               
    $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 * FROM table LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error());

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

    $bgcolor = "#E0E0E0"; // light gray

    echo("<table>");
    
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor.">n<td>");
    echo($row["users"]);
    echo("</td>n<td>");
    echo($row["usersID"]);
    echo("</td>n</tr>");
    }

    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);

?>
 
Last edited:
0
•••
I'd say that you need most everything in that code.
 
0
•••
Yep..... however, there are "easier" ways to do this with much less code ... such as

PHP:
<?php

$page = intval($_GET['page']);

if(!$page || $page == "")
{
  $page = 1;
}

$prev = $page - 1;
$next = $page + 1;
$ppage = 10;
$limit = ($page * $ppage) - $ppage;

$query = mysql_query("SELECT field FROM table") or die(mysql_error());
$num = mysql_num_rows($query);
$num_pages = ceil($num / $ppage);

$link = '';

if($page > 1)
{
  $link .= ' <a href="?page=1">First</a> <a href="?page='.$prev.'">Prev</a> ';
}

for($i = 1; $i <= $num_pages; $i++)
{
  if($page == $i)
  {
    $link .= ' <b>['.$i.']</b> ';
  }
  else
  {
    $link .= ' <a href="?page='.$i.'">'.$i.'</a> ';
  }
}

if($page < $num_pages)
{
  $link .= ' <a href="?page='.$next.'">Next</a> <a href="?page='.$num_pages.'">Last</a>';
}

$sql = mysql_query("SELECT * FROM table LIMIT ".$limit.", ".$ppage) or die(mysql_error());

while($row = mysql_fetch_array($sql))
{
  //Do your thang here
}

//You end up having your link in the $link variable 
//so you could echo it anywhere on down the page....

echo $link;

?>
 
0
•••
I have all the query results set out all I need is to group it, is that the code.

EDIT:

PHP:
  <?php

$page = intval($_GET['page']);

if(!$page || $page == "")
{
  $page = 1;
}

$prev = $page - 1;
$next = $page + 1;
$ppage = 10;
$limit = ($page * $ppage) - $ppage;

$query = mysql_query("SELECT field FROM pm_search") or die(mysql_error());
$num = mysql_num_rows($query);
$num_pages = ceil($num / $ppage);

$link = '';

if($page > 1)
{
  $link .= ' <a href="?page=1">First</a> <a href="?page='.$prev.'">Prev</a> ';
}

for($i = 1; $i <= $num_pages; $i++)
{
  if($page == $i)
  {
    $link .= ' <b>['.$i.']</b> ';
  }
  else
  {
    $link .= ' <a href="?page='.$i.'">'.$i.'</a> ';
  }
}

if($page < $num_pages)
{
  $link .= ' <a href="?page='.$next.'">Next</a> <a href="?page='.$num_pages.'">Last</a>';
}

$sql = mysql_query("SELECT * FROM pm_search LIMIT ".$limit.", ".$ppage) or die(mysql_error());

while($row = mysql_fetch_array($sql))
{





?>


<table width="100%" border="0" cellspacing="0" cellpadding="3" style="border-collapse: collapse" bordercolor="#111111" class="text">
			<? while ($row = mysql_fetch_array($check))
			{ ?>
				<tr>
						<td width="100%">
							<font class="link">
							<a href="<? echo $row[url]; ?>"><? echo $row['title']; ?></a><br>
							</font>
							<? echo $row['description']; ?><br>
							<font class="reallink">
							<? echo $row['url']; ?>
							</font>
						</td>
					</tr>
		<?	}   ?>
				</table>
				<br><br>
				</body>
				</html>
<?	}
}

if ($_GET[act] == "search")
	search();
else
	newsearch();





}

//You end up having your link in the $link variable
//so you could echo it anywhere on down the page....

echo $link;

?>


Thats what I have and all it gives me is a blank screen :S
 
Last edited:
0
•••
You should probably read the tutorial instead of just going to the very end and getting the final code. That way, you'll know how to make it work for your site.
 
0
•••
I read it and configured but all I got was a white screen :S
 
0
•••
If you aren't even getting the page numbers, then your mysql query isn't working correctly. Look through your query and test it out a few other ways.
 
0
•••
Ive tried ever Pagination script I can find nothing works :S
 
0
•••
0
•••
I don't understand PEAR what is it and what am I ment to download from it to help me
 
0
•••
Pear is a PHP class that does wonderous things.
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back