Jump to content

Arranging results


user4fun
 Share

Recommended Posts

I am wondering on how websites do this,exampleyour search qurey returns x amount of resultsthe result will be the page numbers to be displayed with a previosue and an after navigation links.example34 results came back it would bring uppreviouse | 1 | 2 | 3 | 4 | nextand each number would be linked to the range.I am guessing it is not the easiest of codes, but i need a place to start.thank you.

Link to comment
Share on other sites

I am wondering on how websites do this,exampleyour search qurey returns x amount of resultsthe result will be the page numbers to be displayed with a previosue and an after navigation links.example34 results came back it would bring uppreviouse | 1 | 2 | 3 | 4 | nextand each number would be linked to the range.I am guessing it is not the easiest of codes, but i need a place to start.thank you.
here's a link that will help you for sure solve your problem.http://phpsense.com/php/php-pagination-script.htmlbe patient, use some logic and you'll succeed!
Link to comment
Share on other sites

  • 9 months later...

I am trying to use this script but could you explain to me how it should be done with my code please?I have been on this for hours...

<?phpinclude("config.php");$item = $_REQUEST['find'];$kat = $_REQUEST['katt'];$plat = $_REQUEST['plats'];$st = $_REQUEST['status'];if(($kat>'99') && ($plat>'99') && ($st>'99')) {$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat<99 AND plats<99 AND status<99 ORDER BY id desc");}elseif(($plat>'99') && ($st>'99')) {$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat='$kat' AND plats<99 AND status<99 ORDER BY id desc");}elseif(($kat>'99') && ($st>'99')) {$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat<99 AND plats='$plat' AND status<99 ORDER BY id desc");}elseif(($kat>'99') && ($plat>'99')) {$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat<99 AND plats<99 AND status='$st' ORDER BY id desc");}elseif($kat>'99') {$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat<99 AND plats='$plat' AND status='$st' ORDER BY id desc");}elseif($plat>'99') {$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat='$kat' AND plats<99 AND status='$st' ORDER BY id desc");}elseif($st>'99') {$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat='$kat' AND plats<99 AND status=<99 ORDER BY id desc");}else{$result = mysql_query("SELECT *, id AS b_id FROM annons WHERE rubrik LIKE '%$item%' AND kat='$kat' AND plats='$plat' AND status='$st' ORDER BY id desc");}$result2 = mysql_query("SELECT * FROM status, annons WHERE status.id=annons.status");echo "<br \>";?><html><body>----large form, erased----</body></html><?phpecho '<h2>Annonser</h2>';echo '<table cellpadding="2" rules="groups" frame="box" bordercolor="red" cellspacing="0" border="1">';echo '<thead><tr><th width="150px" align="left">Datum</th><th width="350px" align="left">Rubrik</th><th width="50px" align="left">Pris</th><th width="50px" align="left"></th></thead>';echo '<tbody>';while ($add = mysql_fetch_array($result, MYSQL_BOTH)) {  echo "<td>" . $add['datum'] . "</td>";  echo "<td>" . '<a href="open.php?id='.urlencode($add['b_id']).'">' . $add['rubrik'] . '</a>' . "</td>";  echo "<td>" . $add['pris'] . ":-</td>";  echo "<td>" . $add2['status'] . "</td>";  echo '</tr>';  }  echo "</tbody></table>";echo "<br \>";echo "<br \>";mysql_close($con);?>

Link to comment
Share on other sites

If you're trying to use the PS_Pagination class on that link, then instead of querying the database in the if/else block just create the query and save it in a variable. Once you have the query created after the if/else block then you can follow the instructions on that page, the pagination object needs your database connection object, the query you just created, the number of items to show on a page, and the number of page links to show. The paginate function will return a recordset for the current page that you can loop through.

Link to comment
Share on other sites

so I make it like this? $sql = $result;It keeps giving me:Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in F:\xampp\htdocs\list.php on line 207207: while ($row = mysql_fetch_assoc($rs)) {

Link to comment
Share on other sites

Look at the example they have on the page:

<?php	//Include the PS_Pagination class	include('ps_pagination.php');	//Connect to mysql db	$conn = mysql_connect('localhost','username','password');	mysql_select_db('testdb',$conn);	$sql = 'select title from pages';	//Create a PS_Pagination object	$pager = new PS_Pagination($conn,$sql,8,3);	//The paginate() function returns a mysql	//result set for the current page	$rs = $pager->paginate();	//Loop through the result set	while($row = mysql_fetch_assoc($rs)) {		echo $row['title'];	}	//Display the navigation	echo $pager->renderFullNav();?>

The recordset is the return value from the paginate method, in this case $pager->paginate.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...