PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 3rd, 2000, 03:27 AM
wrohner wrohner is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Cape Town, South Africa
Posts: 18 wrohner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello,

I'm wasn't sure whether to post this under the PHP or under the MySQL section of the forums. Since most people (I'm assuming) who write PHP script, also use MySQL, I thought I'd stick with PHP. I'm rather new to both PHP and MySQL and I'd be very grateful to anyone who can help me solve a problem I'm having at the moment. First, I'll give you an introduction to my little project...

I'm developing a database in MySQL that is used to store the song titles of all the MP3s I have on my PC. I've written a basic search feature that works well. The user has 2 options: Either he can type a special "!ALL" "parameter", that I made up, to return all the songs in the database or the user may enter a few characters in the textbox and select "song title" or "artist" etc. from a dropdown to search for a specific song title or artist etc.. Hope you are following so far? Say for example the user presses submit after typing "!ALL" to return all the song titles - there could be hundreds of results. What I want to do now is display 10 results on a page, then on the next page another 10, etc. (like a real search engine!). I've tried doing it with the LIMIT statement, but like I said I'm new to this and discovered that that is not the right way of going about it. My question is this: how would I go about returning 10 matches per page? Do I use hidden form fields? What would the SELECT statement look like? What would the PHP scripting look like to setup the "back" and "forward" navigation between the result for the search?

If you need any more info, let me know. Thanks in advance for your help!

Reply With Quote
  #2  
Old March 3rd, 2000, 03:38 AM
Chrille Chrille is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Location: Sweden
Posts: 384 Chrille User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 20 h 39 m 54 sec
Reputation Power: 14
Hi.

Test using
SELECT * FROM your_datbase LIMIT 0, 30

This will return 30 hits.

Sincerely,
Christoffer
SWEDEN


Reply With Quote
  #3  
Old March 3rd, 2000, 03:44 AM
wrohner wrohner is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Cape Town, South Africa
Posts: 18 wrohner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi again

Thanks for that, but it's not quite right. I wanted something that would return all the rows of the table, but split the results up onto seperate pages. Say for example the SELECT statement returns 100 results, then I want 10 pages each with 10 results on it (continuing on from where the previous page left off) - just like a web search engine does. My real problem lies with what goes into the select statement and what is the PHP code I must use to control the navigation between the seperate pages of results. Also, what are the variables that I will need to keep all this together.

Thanks again,
Warren

Reply With Quote
  #4  
Old March 3rd, 2000, 04:55 AM
falcon falcon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 1999
Location: UK
Posts: 50 falcon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 33 sec
Reputation Power: 14
OK, I am going to try and explain this as clear as I can, this is solution I have thought up in the last few seconds, this is not to say that it is the most ideal way.

With that small disclaimer out of the way here is how you could do it. As I don't know mysql as yet I'll write it in some psuedo type code.

Select all the results from the database. Put all the results from the database into a array.

Query the size of the array, if that is larger than 10 then display the first ten results. Also echo out images depending on what page you are on (dictated by a post value).

Example:

max_val = post_value x 10
loop = 0;
while loop < sizeof(array) && loop != max_val
echo out array[loop]
end loop

if post_value != "" | | post_value != 1
//echo out prev image
echo <link?pagenum=post_value-1><image>
end if

if NOT(more results to work out)
// echo out next iamge
echo <link?pagenum=post_value+1><image>
end if

A bit rough and ready, but not bad for making it up on the spot. I'm sorry its not more detailed but I hope it helps.

Falcon

Reply With Quote
  #5  
Old March 3rd, 2000, 07:38 AM
wrohner wrohner is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Cape Town, South Africa
Posts: 18 wrohner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok thanks falcon, I'm going to give that a try and let you know how it works out. Anyone else may still offer their help as I want to see how many different ways this can be done.

Thanks to everyone,
Warren

Reply With Quote
  #6  
Old March 3rd, 2000, 07:41 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
I've written an article at www.phpbuilder.com that deals with just this matter. It's a bit rough written on a Sunday morning before coffee (what do you expect, I did it for free..), but it seemed to be an area where many questions have arisen.

The sample code is NOT intended for production but more as an algorithm to describe HOW to build a multi-page result script including PREV 1 2 3 4 NEXT type indexing.

HTH

Reply With Quote
  #7  
Old March 3rd, 2000, 07:51 PM
amodi amodi is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Location: Gorakhpur,U.P.,India
Posts: 24 amodi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You are requested to visit http://www.bharatyellowpages.com and view a category that has the maximum no of entries. Multiple display page has been implemented there. If you find it useful please let me know.i can give u the code which implements the same.

Rgds



------------------
Anish Modi
Infotech World
India

Reply With Quote
  #8  
Old March 3rd, 2000, 11:23 PM
Randy's Avatar
Randy Randy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 1999
Location: St. George, UT 84770
Posts: 33 Randy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rod k:
I've written an article at www.phpbuilder.com that deals with just this matter. It's a bit rough written on a Sunday morning before coffee (what do you expect, I did it for free..), but it seemed to be an area where many questions have arisen.

The sample code is NOT intended for production but more as an algorithm to describe HOW to build a multi-page result script including PREV 1 2 3 4 NEXT type indexing.

HTH
[/quote]

Rod,

I noticed you have a PHPBuilder address. How are you involved there? Would love to work with you on other tutorials (not necessarily for free). We don't have backing like Internet.com, but we're trying

Randy


Reply With Quote
  #9  
Old March 4th, 2000, 03:37 AM
wrohner wrohner is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Cape Town, South Africa
Posts: 18 wrohner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks everyone for all your help. Rod K, I saw your column at PHPBuilder last night coincedentally. How weird is that?

Amodi, I would love to see the code that you used to implement the search pages at http://www.bharatyellowpages.com...Thank you for your help.

Ok you guys, take care

Reply With Quote
  #10  
Old March 4th, 2000, 05:24 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
Randy,

I'm not really affiliated at all. Tim Purdue, founder of PHPBuilder, offered a couple of the regular contributors there the address. I took it sort of as a vanity thing

I would like to write some more tutorials (I've got some ideas for "obscure" mysql functions) but until I clear up some things on my plate...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > How do I return 10 results per page using SELECT statement?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap