General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 11th, 2003, 04:27 AM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Talking Posting an array to the next page...

Hi All,

A real simple question for most of you...

My page basically does a query and then displays a defined amount of results, 20 if not defined, and then displays a next, previous, first and last page link. So the first page will display 0-19, second will display 20-39, so on and so forth. But at the mo I am making the page do the same query on every page (i.e. get all the results), and then only display the first 20 results, or next 20 results dependant on which page its on. Obviously this is a lot more processing then is required. I have all the query results i need going into an array, but how do I make the next page view this array?? I believe that I need to make it into a superglobal variable, but how do i achieve this? any ideas??

Thanks All,

Harvey

Reply With Quote
  #2  
Old July 11th, 2003, 04:50 AM
dhaval_adams dhaval_adams is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Dubai
Posts: 24 dhaval_adams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to dhaval_adams
I don't think that's the rite way of doin...

Hi,

Well you could retrieve all the records from the database and store it in a variable, then register the variable in session but then that isn't the rite way of doin it...
Each time you declare a variable in php, it allocates memory for that particular variable..( I guess that's what my friend had explained to me) so it's not worth doing it...just do the normal way... "select whatever from wherever limit first_rec, size" ...

Anywayz, for ur info sake..this is how u can store the records from the database into ur array...
<?php

$connect = mysql_connect($dbhost,$dbuser,$dbpass);
$query = "select whatever from wherever";
$execute = mysql_db_query($dbname,$query);
$rows = mysql_num_rows($execute);
if($rows != 0) {

for($i= 0; $i<$rows; $i++) {
$result = mysql_fetch_array($execute);

$temparray[$i] = $result["fieldname"];


}

//Now just register this variable in session....
$_SESSION["data_var"] = $temparray;


/*
Then you will need to write the code to limitin the display...which maybe someone else can write for you as I am runing short of time...
/*


} else {
echo "No rows found";
}

?>

Reply With Quote
  #3  
Old July 11th, 2003, 05:31 AM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Cheers for that,

I have already written my sorting algorithm and it all works fine, but didn't think about limiting the query, a very good idea. At the moment i'm getting all the results and then displaying a selected few, and doing the same query again (getting all the results) but displaying the next batch, too much processing!!

I'll have a look at limiting...

Cheers,

Harvey

Reply With Quote
  #4  
Old July 11th, 2003, 05:41 AM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
must be a way??

...ah ha, but the problem with limit is that if it is used with "order" then it will only order the first set of rows, instead of ordering the whole table and then giving you the first batch. Does anyone know of a way aroung this? So, instead of posting an array of all the results to the next page (too heavy on memory) or doing the same query (getting all the results of the query) on every page or using limit as it doesn't order the whole table. Does anyone know of another way??

Cheers,

Harvey

Reply With Quote
  #5  
Old July 11th, 2003, 07:54 AM
dhaval_adams dhaval_adams is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Dubai
Posts: 24 dhaval_adams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to dhaval_adams
Hi,

I guess you should have a look at the pagination tutorial at www.phpfreaks.com and I never had a problem with limit and ORDER in the same query...it works fine..
"select * from table where .... ORDER BY whatever limit 0,5" works fine...even when at the next page it is 5,10 and 10,15 and whatever...

I hope if this is what you are talkin abt...

Reply With Quote
  #6  
Old July 11th, 2003, 09:08 AM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hi ya,

I haven't actually experienced or tested the mysql function limit but the following page explains the problem in the MySQL manual...
http://www.mysql.com/doc/en/LIMIT_optimisation.html
...I shall test it though and let you know how i get on...

Cheers,

Harvey

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Posting an array to the next page...


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT