Jump to content

limited results per page


blyz

Recommended Posts

This is pagination, you should search for it on google, its not that difficult to impliment. You just have to use $_GET to get the page number then set how much you want per page and then just use a loop and ifs.

 

eg

 

<?php
$page = $_GET['page'];
if(empty($page))
{
$page = 1;
}
$query = //you query
$pages = mysql_num_rows($query);
$ppp = 5; // post per page
$numofpages = ceil($pages/$ppp);
if($page == 1)
{
echo "Prev ";
} else
{
	$prev_page = $page-1;
	echo "<a href=\"{$PHP_SELF}?page={$prev_page}\">Prev </a> | ";
}
for($i = 1; $i <= $numofpages; $i++)
{
if($i == $page)
{
	echo "{$i} | ";
} else
	{
		echo "<a href=\"{$PHP_SELF}?page={$i}\">{$i}</a> | ";
        }
}
if($page == $numofpages)
{
echo "Next ";
} else
{
	$next_page = $page+1;
	echo "<a href=\"{$PHP_SELF}?page={$next_page}\">Next</a> | ";
}
?>

 

Hope that helps

 

EDIT: Sorry there were a few typos

 

~ Chocopi

Well I only posted that code to  gove you the general idea, I personally do it differently but this will work for a very basic pagination.

 

If your going to use this then all you have to do is get the number of results in your table that you are going to echo thats what the query and mysql_num_rows is for. So you just need a way to find the number of rows in you downloads.php/applications.php

 

I hope that clears it up ;D

 

~ Chocopi

Hmm, i dont really understand im a php noob, their are 20 of these on the dowloads page

<table width="409" height="115" border="1" bgcolor ="black">

  <tr>

    <td width="70" height="84"><img src="/preview.jpg"></td>

    <td width="323"><h2> Name. </h2>

    </td>

  </tr>

  <tr><b>

    <td><img src="/sg.jpg"></td>

    <td>Size:   

         

   

         <a href="downloadurl" target ="_blank">DOWNLOAD NOW!</a></td>

  </tr>

</table></b>

 

so should i give each table a variable ?

well I think the best way would be to put the info into an array

 

$array = array(0 => "some Code", 1 => "some code");
$array_num = count($array);

 

then use a for loop to get it all

 

for($i = 0; $i <= $array_num; $i++)
{
   echo $array[$i];
}

 


 

or

 

we could just put a few if statements around saying

 

$num = 2; // some random number
if($page == $num)
{
  echo "your content";
}

 

~ Chocopi

so we just have to put that into an array and we will be sorted ;D

 

<?php
$array = array(0 => array(0 => "description", 1 => "link"), 1 => array(0 => "description2", 1 => "link2"), 2 => array(0 => "description3", 1 => "link3"));
$array_num =  count($array);
for($i = 0; $i <= $array_num; $i++)
{
echo "<table>";
echo "<tr>";
echo "<td>";
echo $array[$i][0];
echo "</td>";
echo "<td>";
echo $array[$i][1];
echo "</td>";
echo "</tr>";
echo "</table>";
}
?>

 

There we go, I think that should be what you wanted, then just add the description and link and change the html.

 

If you need anymore help, you know where to ask.

 

BTW, sorry for not understanding what you meant ;p

 

~ Chocopi ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.