pagination - missing result

hello, and thanks for any help you guys can give me in advance!
i have this pagination script, cobbled together from various tutorials as this is my maiden voyage into custom php stuff. what it is doing is taking form input ($terms1) then doing a search. the results come up here and are paged, etc.

the problems:

  1. im missing the first result, and that it only displays limit-1. so if i say i want 10 results per page, im only getting 9.

  2. if i search and get 1 result, it says it finds one but doesnt display it.

here is the code:

[php]<?php

// Connects to your Database
include ‘config/config.php’;
include ‘config/opendb.php’;

$terms1 = $_POST[‘text_input’];

$query = “SELECT * FROM master
WHERE title LIKE ‘%$terms1%’
AND sale_price != ‘0’
ORDER BY ‘sale_price’ ASC”;
$result = mysql_query($query);
$numrows=mysql_num_rows($result);

echo(“

You searched for: “);
echo($terms1);
echo(”

”);
echo(“

We found:”);
echo($numrows);

//if no results
if ($numrows == 0)
{
echo “

Sorry, your search: “” . $terms1 . “” returned zero results

”;
}

// begin pagination
// determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}

// rows to return
$limit=10;

// begin to show results set
$count = 1 + $s ;

// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die(“Couldn’t execute query”);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row[“title”];

echo("

".$row[‘title’] . " ");

echo(“

Sale Price: $”.$row[‘sale_price’] . “

”);
$count++ ;
}

$currPage = (($s/$limit) + 1);

//break before paging
echo “
”;

// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print "

 <<
Prev 10
&nbsp ";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

// not last page so give NEXT link
$news=$s+$limit;

echo " Next 10 >>";
}

$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo “

Showing results $b to $a of $numrows

”;

//end pagination

// debug
echo(“

Query: $”.$query . “”);
include ‘config/closedb.php’;
?>[/php]

u may have copyed from too many tutorials.

[php]while($row = mysql_fetch_array($result, MYSQL_ASSOC))

// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row[“title”];

echo("

".$row[‘title’] . " ");

echo(“

Sale Price: $”.$row[‘sale_price’] . “

”);
$count++ ;
}[/php]

there u see that u included while twice.
thereby u included the mysql_fetch_array() 2 times before puting out the first result.
as mysql_fetch_array() alway grabs the next row u always start with the second.

just delete the line:
[php]while($row = mysql_fetch_array($result, MYSQL_ASSOC))[/php]
… then it’ll work.

P.S.: plz use the [php ] [/php] markup

P.P.S.: u forgot 2 close ur first

tag.

thank for you very much for such speedy help
i feel dumb but hey, i have to start somewhere i suppose

again thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service