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

Link to comment
Share on other sites

i forgot to mention my download section doesnt use mysql, basically i direct them to a page called downloads.php, and this includes a page called applications.php which has 20 little tables each with image and download link.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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