Hi! I will post here a code for separating the results of MySQL in pages.
You ask: Why separete?
I answer: Imagin that you have 1523 results to display. I dont have to say anything. =P
Here is it.
-------------------------------------------------------------------
CODE
<?php
$conect = mysql_connect("host","user","password");
$select_db = mysql_select_db("database");
$query = "SELECT * FROM mytable";
$results = "15"; //Number of results displayed per page.

if (!$page) {
    $counter = "1";
} else {
    $pcounter = $page;
}

$start = $counter - 1;
$start = $counter * $results;

$limit = mysql_query("$query LIMIT $start,$results");
$all = mysql_query("$query");

$total_registers = mysql_num_rows($all);
$total_pages = $total_registers / $results;

//---------NOW LETS SHOW EVERYTHING!! =D

while ($data = mysql_fetch_array($limit)) {
    $name = $data["name"];
    echo "Name: $name<br>";
}


$prev = $counter -1;
next = $counter +1;
if ($counter>1) {
    echo " <a href='?page=$prev'><- Previous</a> ";
}
echo "|";
if ($counter<$total_pages) {
    echo " <a href='?pagina=$next'>Next -></a>";
}
?>


[[MODERATOR PLEASE DELETE THIS POST AND EDIT MY FIRST POST]]
CODE
<?php
$conect = mysql_connect("host","user","password");
$select_db = mysql_select_db("database");
$query = "SELECT * FROM mytable";
$results = "15"; //Number of results displayed per page.

if (!$page) {
    $counter = "1";
} else {
    $counter = $page; //CHANGE 'pcounter' to 'counter'
}

 

 

 


Reply