/    Sign up×
Community /Pin to ProfileBookmark

first 10 results

Hi all!!

I am having some hard time to create a script that will display the first 10 results of a query having a link to next 10, and so on. Just like search engines do to list the results.

Can i get some help?

Cheers

Sandro27

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@HaganeNoKokoroOct 18.2004 — In MySQL (I really don't know much about other DBMS) this is accomplished using the LIMIT in the sql statement. For example, if your query isSELECT * FROM sometable WHERE somecolumn=somevalueThen you would change it toSELECT * FROM sometable WHERE somecolumn=somevalue LIMIT start, countSo say you use 10 for [font=courier]start[/font] and 5 for [font=courier]count[/font]. Then it would start at the 10th result and return the next 5. If you don't specify [font=courier]start[/font] then it will just start with the first result.

So what you do is pass the current start value through the URL and use it in your query. There are some (slightly) more complicated things you can do, of course, like if you count the total results that would be returned with no limit, you can calculate the total number of pages and create a link to each page. Or allow users to set how many results per page, etc.

Of course, you will have to execute the query every time, so when someone clicks the link to the next page, the query will run again, but with different limit values.

I also found a little reference on limiting results in other DBMS

http://sqlzoo.net/howto/source/s.pl.htm?file=tip857849
Copy linkTweet thisAlerts:
@sandro27authorOct 18.2004 — thanks
Copy linkTweet thisAlerts:
@MallerOct 18.2004 — You might wanna take a look at this article too

http://www.phpfreaks.com/tutorial_comment/73/1/672.php#672
Copy linkTweet thisAlerts:
@sandro27authorOct 20.2004 — I am having problems with this script:

<?

if(!isset($_GET['page'])){

$page = 1;

} else {

$page = $_
GET['page'];

}

$max_results = 10;

$from = (($page * $max_results) - $max_results);

?>

I got this at: http://www.phpfreaks.com/tutorial_c...3/1/672.php#672

But it doesn´t allow me to get the member_id form another file ,like:

<?

$id=$_GET['member_id'];

echo "<a href='member_account.php?member_id=$id'>back to account</a>";

?>

Instead it shows the page number: $page = $_GET['page'];

How can I get the member_id?

Cheers
Copy linkTweet thisAlerts:
@sandro27authorOct 20.2004 — Let´s say I want to carry the id(?member_id=$id) inside the following url:

<a href="".$_SERVER['PHP_SELF']."?page=$prev">

Is it possible?
×

Success!

Help @sandro27 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.19,
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,
)...