Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pagination - Again 1

Status
Not open for further replies.
Jul 28, 2005
358
FR
OK, I knwo that pagination has been dealt with loads of times bur I am really not getting anywhere with my own script so here goes.

I have this code that pulls out data and displays the search results (display is called from an include file which I won't include here)

Code:
require('conf.php');
	
include('head.html');
	//query database for propeties
	$people1 =$people ;
	$people1 ++;
	$query="SELECT pid, pname, pshortdescription, picture, sleeps, baths from properties WHERE (sleeps = '$people' or sleeps = '$people1')";
	$result= mysql_query ($query); 
	while  (list($pid, $pname, $pshortdescription, $picture, $sleeps, $baths ) = mysql_fetch_row($result)){
	
		include('azur/tpl/displayresults.tpl');
	?></p><?
	

  	

	}
	include('footer.html');
	?>

I want to only display 10 results and have links to the next results pages etc.

Can anyone help at all. Many thanks in advance.

Richard
 
Had a look at it but it just displays garbage on my screen. Don't know if it is anything to do with my include files but they work fine on my script.
 
Had a look at it but it just displays garbage on my screen.
I don't understand.

I just now created and populated the table by using the instructions in the FAQ, then created the script by copying-and-pasting the FAQ script code into a file. It worked correctly for me.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sorry, probably not the best reply from me.

Ok, I took your code, and then replaced the sql query with my own (see above) Where you had your results displayed I changed them for my include file which displays my results in the way I want.

Unfortunately when I ran the script, it displayed a load of the code in the page. I checked the php and all my begin and end tags are in the right place so I haven't got a clue why it messes up. Must be something to do with my script, I wasn't trying to imply that yours doesn't work.

I've just put the code back in, and now i get this

Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in search.php on line 91

Where I have this as the query:
Code:
$data_query = "SELECT * from properties WHERE (sleeps = '$people' or sleeps = '$people1') " . $limit_start . ", " . $records_per_page;
$rh = mysql_query ($data_query);


print '<html><body><table width="100%" border="1">';


//output the required records
while ($word_data = mysql_fetch_array($rh))

The $rh = mysql_query ($data_query); being line 91.

This is driving me up the wall but I am sure it's something I'm missing.

If it helps, here is my complete version of your code

Code:
<?
require('conf.php');
	
include('azur/head.html');
	
	include('azur/footer.html');
	//?>
	
	//<?php
/* Data paging script
   2004-06-28 by sleipnir214
   This script is in the public domain.
   
   CAUTION:  This script works on my system -- but it could blow yours to smithereens.
   Therefore, no waranty is expressed or implied as to how safe it will be for you to use.
   Use this code with trepidation and circumspection.
 */
 
 
//variables for connecting to MySQL Removed as they are in the conf file


//set the number of records per page
$records_per_page = 10;


//connect to MySQL Removed as they are in the conf file



//find out how many records are in the table
$count_query = "SELECT pid, pname, pshortdescription, picture, sleeps, baths from properties WHERE (sleeps = '$people' or sleeps = '$people1')";
$rh = mysql_query ($count_query);
list ($record_count) = mysql_fetch_array($rh);


//calculate the maximum "page" that can be displayed.
$max_pages = floor($record_count / $records_per_page);


//This logic takes care of reacting to input.
if (isset($_GET['page']))
{
    if ($_GET['page'] > 1)
    {
        if ($_GET['page'] > $max_pages)
        {
            $current_page = $max_pages;
        }
        else
        {
            $current_page = $_GET['page'];
        }
    }
    else
    {
        $current_page = 1;
    }
    
    $limit_start = $current_page * $records_per_page;
}
else
{
    $limit_start = 0;
    $current_page = 1;
}


//query the database for the required records
$data_query = "SELECT * from properties WHERE (sleeps = '$people' or sleeps = '$people1') " . $limit_start . ", " . $records_per_page;
$rh = mysql_query ($data_query);


print '<html><body><table width="100%" border="1">';


//output the required records
while ($word_data = mysql_fetch_array($rh))
{
    include('azur/tpl/property_details_list.tpl');
}


//this is the logic for the "previous" link display
print '<tr><td width="50%" align="center">';
if ($current_page > 1)
{
    print '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($current_page - 1) . '">previous</a>';
}
else
{
    print '&nbsp;';
}
print '</td>';


//this is the logic for the "next" link display
print '<td width="50%" align="center">';
if ($limit_start + $records_per_page < $record_count)
{
    print '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($current_page + 1) . '">next</a>';
}
else
{
    print '&nbsp;';
}
print '</td></tr></table><body></html>';
include('azur/footer.html');
?>

Thanks loads,

Richard
 
I knew it had to be me!! Forgot a few bits and pieces but getting there now. Thanks a lot.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top