Jump to content

pages and results per page


squiblo

Recommended Posts

I would like to just show 10 results per page but how do I do this, and how do I create the pages?

 

<font face="arial">

<?php

//get data
$button = $_GET['submit'];
$search = $_GET['search'];

if (!$button)
header("location:unititled.php");
else
{
if (strlen($search)<3)
	header("location:unititled.php");
else
{
	echo "";

	//connect to our database
	mysql_connect("localhost","","");
	mysql_select_db("");


		//explode our search term
		$search_exploded = explode(" ",$search);

		foreach($search_exploded as $search_each)
		{

		//construct query
		$x++;
		if ($x==1)
		    $construct .= "username LIKE '%$search_each%'";
		else
		    $construct .= " OR username LIKE '%$search_each%'";			
	    
		}


	//echo out construct

	$construct = "SELECT * FROM members WHERE $construct";
	$run = mysql_query($construct);

	$foundnum = mysql_num_rows($run);

	if ($foundnum==0)
	   echo "No results found.";
	else
	{
	   echo "You searched for <b>$search</b><br>$foundnum result(s) found!<p><hr size='1' width='300'color='#E6E6E6'>";
	   
	   while ($runrows = mysql_fetch_assoc($run))
	   {
	 //get data
                $state = ucwords($runrows['state']);
                $url = $runrows['url'];
                $username = ucwords($runrows['username']);
                $imagelocation = $runrows['imagelocation'];
                if ($imagelocation == "") {
                $imagelocation = "./profileimages/box.png";
} 


	echo "
                <img src ='$imagelocation' width='100' height='105' border='0' align='left' style='padding-right:10px'><br>
	<b>$username</b><br>
	$state<br>
	<a href='$url'>View Profile</a><br><br><br>
	<hr size='1' width='300' align='left' color='#E6E6E6'>
      		   
      		
      		
        	
  		";

  		
             }


           }   



        }	



}	



?>
</font>


Link to comment
https://forums.phpfreaks.com/topic/168174-pages-and-results-per-page/
Share on other sites

Theres nothing in your code that would deal with the paging ? The basics of creating paging would go about follorwing way...

1. You get result amount and calculate max pages.

2. Based on max pages you create links for the paging.

3. When link is clicked you calculate the offset and limit values for SQL query based on the page.

4. Run a query eg. "SELECT somevalues FROM sometable WHERE here_year_search_conditions LIMIT $offset, $rowsPerPage"

 

(and of course between this process you have to store soemwhere your search results so they won't disappear during page change. eg. in session variables)

 

Also there is a lot of tutorials if you search eg. with words "paging php" or "php paging tutorial", also there is available ready codes for that.

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.