/    Sign up×
Community /Pin to ProfileBookmark

Can’t split SQL query results to multiple pages

Hello there,
I have a website that allows to search within a database of mine.
The results are displayed in a table, and I would like to split the results to pages so it’ll be 10 results per page.

Before I display the code here’s an explanation of it:
$result2 is my sql query (assume that it’s valid).
$perpage is initially 10 (defined by me).
$x is a value of a dropdown box from a form in another page.
$y is a value of a textarea from the same form.
$z as $x only from another dropdown box (same form).
$r and $t as $y only from other textareas (same form).
$s is an ARRAY of checked checkboxed from the same form.

Here’s the code part responsible of the pages spliting:

[CODE]$nump = mysql_num_rows($result2);
$nump = $nump / $perpage;
if(intval($nump) != $nump)
$nump = intval($nump) + 1;
for($I = 1; $I<= $nump; $I++)
{
if($page != $I) {
if (count($s) > 0)
echo “<A HREF=$PHP_SELF?page=$I&x=$x&y=$y&z=$z&t=$t&r=$r&s=$s>$I</A>”;
else
echo “<A HREF=$PHP_SELF?page=$I&x=$x&y=$y&z=$z&t=$t&r=$r&s=’ ‘>$I</A>”;
}
else
echo $I;
if($I != $nump)
echo ” – “;
}
echo “<br /><br />”;
$lim1 = ($page – 1) * $perpage;

$query2 .= “LIMIT $lim1,$perpage “;
$result2 = mysql_query($query2);[/CODE]

What I get is this:
In the first page, everything’s ok and it displayed the first 10 results. BUT, it the second one, it gives me an error that the query is not valid and it gives me a message as if no results found.

I’ll be happy to recieve some help.
Thanks in advance

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MarPloSep 11.2012 — Hi

The address from "href" must be between quotes.
echo "&lt;A HREF="$PHP_SELF?page=$I&amp;x=$x&amp;y=$y&amp;z=$z&amp;t=$t&amp;r=$r&amp;s=$s"&gt;$I&lt;/A&gt;";
You must get data from url, with $_GET , and use it in your query.

- From my opinion, better try and use a pagination script, for exemple this: [url=http://www.coursesweb.net/php-mysql/pagination-class-script_s2]PHP Pagination Class[/url] .
Copy linkTweet thisAlerts:
@ydan87authorSep 11.2012 — I'll give it a try. Thank you ?
×

Success!

Help @ydan87 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...