|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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"; } ?> |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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... |
|
#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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Posting an array to the next page... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|