NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page mysql, search, ammount per page and total results

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
4 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-01-2004, 02:33 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer

mysql, search, ammount per page and total results


hey people

wondered if you could help me

right ive got a sql query that searches a database, now i want to do is do an advanced search so the user can refine it

ive got the ammount per page of results

????: NamePros.com http://www.namepros.com/programming/19184-mysql-search-ammount-per-page-total.html
this is done by adding and removing from the limit 0 , 10 at the end of the sql code

ive done this bit now what i need to do is make a way so if they specify a limit of 40 results get the query to stop when it hits the 40th result if it exists, if you get me

any ideas?
ive thought about a while but im not sure how it would be done if they didnt specify a limit (ie show all the results)

any suggestions weclome

thanks
adam
adam_uk is offline  
Old 02-01-2004, 07:55 PM   #2 (permalink)
NamePros Regular
 
CreativeLogic's Avatar
Join Date: Sep 2003
Posts: 889
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
 



Do you have a unique id field in your table? If so it could be easy!
__________________
Online Time Tracking :)
CreativeLogic is offline  
Old 02-01-2004, 10:56 PM   #3 (permalink)
RyanPrice.ca - Developer
Join Date: Dec 2003
Posts: 1,328
Jeanco is a jewel in the roughJeanco is a jewel in the roughJeanco is a jewel in the rough
 



just use some php... something like:

PHP Code:
if ($limit == "") {
????: NamePros.com http://www.namepros.com/showthread.php?t=19184
   
CODE FOR CHOOSING A DEFAULT NUMBER TO DISPLAY
}
else {
   
CODE FOR DISPLAYING THEIR SELECTED NUMBER

__________________
Ryan Price - Webmaster
www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign
Jeanco is offline  
Old 02-01-2004, 11:48 PM THREAD STARTER               #4 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
Quote:
Originally posted by WhSox21
Do you have a unique id field in your table? If so it could be easy!
yeh i do its called id
????: NamePros.com http://www.namepros.com/showthread.php?t=19184

jeanco, can u show me more that way, coz im looking at thinking your going to place a sql query there, if so i dont think it will work
adam_uk is offline  
Old 02-02-2004, 04:10 AM   #5 (permalink)
NamePros Regular
 
CreativeLogic's Avatar
Join Date: Sep 2003
Posts: 889
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
 



I'm not sure if this will work or not for what your trying, I have more ideas though too.

Make a query to get the id of the thing found.
ie:
$sql = "SELECT id FROM table WHERE search='$found' ORDER BY id";
$rs = mysql_query($sql, $cn);
$row = mysql_fetch_assoc($rs);
$id = $row['id'];

$sql = "SELECT * FROM table WHERE id<='$id' ORDER BY id";
... return the rest of your results like you normally would ...
__________________
Online Time Tracking :)
CreativeLogic is offline  
Old 02-02-2004, 04:25 AM   #6 (permalink)
NamePros Regular
 
nicholas's Avatar
Join Date: Dec 2003
Location: The Beach
Posts: 584
nicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of light
 



Adam, this is really just a case of putting a variable in place of your limiter (in this case, the number 10). THe content of that variable is of course whatever your user chose (from an html form).

So for example, let's call your variable "$limiter", then your sql statement would simply be:

PHP Code:
mysql_query("SELECT * FROM your_database WHERE your_conditionals_here = 'your_conditionals_here' LIMIT 0, $limiter"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=19184
That's it.

Or, if you'd also like to let the user control at what row number to start counting (the 40) from, just use another variable (let's call it say, $rowstart):


PHP Code:
mysql_query("SELECT * FROM your_database WHERE your_conditionals_here = 'your_conditionals_here' LIMIT $rowstart$limiter"); 
nicholas is offline  
Old 02-02-2004, 05:04 AM THREAD STARTER               #7 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
thanks for your input

the problem is though that the limit 0, $limiter is already in use for the page numbers

so next page would turn the query from limit, 0 10 to limit 10, 20 and so on

so unless theres another way to do the page numbers im not sure how i would do it

thanks adam
adam_uk is offline  
Old 02-02-2004, 06:48 AM   #8 (permalink)
NamePros Regular
 
nicholas's Avatar
Join Date: Dec 2003
Location: The Beach
Posts: 584
nicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of light
 



Unless I read you incorrectly (short of you posting your code here), why don't you add the current value of the "limit" variables in your environment (URL) string (like for a GET or POST), and just extract the value from every page, so that say, if you set $limiter to increment by say, 40 records at a time, you just add that for the next page's $rowstart and pass it via the environment string (like a GET or POST).

You want to retain the same quantity of rows to show, so $limiter remains the same throughout.

What you'd like to do however (if I read you correctly) is that you want to dynamically and automatically update the start of the record set you're showing, so $rowstart is what you increment:

PHP Code:
 $rowstart += $limiter
????: NamePros.com http://www.namepros.com/showthread.php?t=19184
nicholas is offline  
Old 02-02-2004, 09:22 AM   #9 (permalink)
NamePros Regular
 
CreativeLogic's Avatar
Join Date: Sep 2003
Posts: 889
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
 



Quote:
Originally posted by nicholas
PHP Code:
mysql_query("SELECT * FROM your_database WHERE your_conditionals_here = 'your_conditionals_here' LIMIT 0, $limiter"); 
That is actually incorrect. It should be:
PHP Code:
mysql_query("SELECT * FROM your_table WHERE your_conditionals_here = 'your_conditionals_here' LIMIT 0, $limiter"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=19184
__________________
Online Time Tracking :)
CreativeLogic is offline  
Old 02-02-2004, 10:20 AM   #10 (permalink)
NamePros Regular
 
nicholas's Avatar
Join Date: Dec 2003
Location: The Beach
Posts: 584
nicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of light
 



LOL actually that's a just a semantics issue- the use of "your_database" must be misleading indeed but it isn't meant to be taken literally since it's a reference to whatever code is actually used. but please don't let that distract you from the point, which not about the syntax, but rather about one solution of using variables to limit mysql output properly across pages, which in this example is "LIMIT $rowstart, $limiter", and a note to increase $rowstart by $limiter via passage to the URL/environment string (or decrease it appropriately for a link to the "previous" page), and so on.

Note too to make sure $rowstart does not overshoot the number of rows returned.
__________________
Newsback.com -- Commentary and backstories of the news
-----------------------------------------------
nicholas is offline  
Old 02-02-2004, 10:48 AM THREAD STARTER               #11 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
Quote:
Originally posted by nicholas
Unless I read you incorrectly (short of you posting your code here), why don't you add the current value of the "limit" variables in your environment (URL) string (like for a GET or POST), and just extract the value from every page, so that say, if you set $limiter to increment by say, 40 records at a time, you just add that for the next page's $rowstart and pass it via the environment string (like a GET or POST).

You want to retain the same quantity of rows to show, so $limiter remains the same throughout.

What you'd like to do however (if I read you correctly) is that you want to dynamically and automatically update the start of the record set you're showing, so $rowstart is what you increment:

PHP Code:
 $rowstart += $limiter
????: NamePros.com http://www.namepros.com/showthread.php?t=19184

ahhhhhh

im a nugget!!!! i seriously am

thanks

think uve just awnsered my question
adam_uk is offline  
Old 02-02-2004, 11:05 AM   #12 (permalink)
NamePros Regular
 
CreativeLogic's Avatar
Join Date: Sep 2003
Posts: 889
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
 



I was trying to make things WAAAY more complicated than they really were.
__________________
Online Time Tracking :)
CreativeLogic is offline  
Old 02-02-2004, 11:22 AM   #13 (permalink)
NamePros Regular
 
nicholas's Avatar
Join Date: Dec 2003
Location: The Beach
Posts: 584
nicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of lightnicholas is a glorious beacon of light
 



Hey you're welcome .. don't worry we all go through those days where things like a missing semicolon or dot can give you the fits

Good luck!
__________________
Newsback.com -- Commentary and backstories of the news
-----------------------------------------------
nicholas is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:13 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger