Computer Science Canada

Displaying page (like google...)

Author:  Amailer [ Tue Jul 08, 2003 10:50 am ]
Post subject:  Displaying page (like google...)

You know if you search for a result and there are over...idk over 10 or 20, Google displays the page numbers? And click them and you go to the page which displays the result, i want to know how to creat something like that.

Any help?

Author:  Amailer [ Tue Jul 08, 2003 11:06 am ]
Post subject: 

NEVER MIND CLOSE THIS,
I already made my own, heeh took a bit but i figured it out Smile

Author:  Evil_striker [ Tue Jul 08, 2003 12:53 pm ]
Post subject:  GOOD FOR U

U found out on your OWN!

Author:  Homer_simpson [ Tue Jul 08, 2003 1:22 pm ]
Post subject: 

care to share...?

Author:  Amailer [ Tue Jul 08, 2003 1:26 pm ]
Post subject: 

With help from another site (well it really is editied for my use)
i made this:

code:

....
$order_by = "ORDER BY 'id'";
$sort_order = "DESC";



//select a row here and so we can move on
$query = "SELECT count(*) FROM news";
if(!$query) error_message(sql_error());

$result = mysql_query($query);


//Then lets display the number of logs
//after that we will put a limit to the page

$query_data = mysql_fetch_row($result);
$total_num_user = $query_data[0];

$query1= "SELECT * FROM news";

$numresults=mysql_query($query1);
$numrows=mysql_num_rows($numresults);



if (empty($offset))
{
$offset=0;
}




// The continuing next-prev code

$pages=intval($numrows/$limit);

if (($pages!=0 and $pages!=1) or ($pages==1 and ($numrows%$limit)))
{
if ($offset!=0)
{
$prevoffset=$offset-$limit;
$dis .=  "<a href=\"$PHP_SELF?module=news&offset=$prevoffset\">Previous</a> ";
}

if ($numrows%$limit)
{
$pages++;
}

for ($i=1;$i<=$pages;$i++)
{
$newoffset=$limit*($i-1);
If ($offset!=$newoffset)
{
$dis .=  "<a href=\"$PHP_SELF?module=news&offset=$newoffset\">$i</a> ";
}
else
{

$page_num = $i;

$total_num_page = $last_page_num = ceil($total_num_user/$records_per_page);
               
html_header();
$displays .= "<center><b><u>Displaying the page $page_num out of $last_page_num.</u></b></center>\n";

html_footer();

$dis .= "<b>$i</b> ";
}
}

if ($pages!=1 or (($pages==1 and ($numrows%$limit))))
{
if (($offset+$limit)<$numrows)
{$newoffset=$offset+$limit;
$dis .= "<a href=\"$PHP_SELF?module=news&offset=$newoffset\">Next</a>";
}


$result = mysql_query("SELECT * FROM news $order_by $sort_order LIMIT $offset, $limit");
while($row = mysql_fetch_array($result)) {

...


SOME STUFF OVER THERE IS ATTIOTINAL SINCE IT WAS WORKING A DIFFRENT WAY BEFORE AND THEN I JUST CHANGED IT Smile


: