473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

2 times same query, once with limits

I've a query quite important to execute.

I've to fill an array with all result, so the query is called once wich
returns all ID's

Then I call the same query a second time as I shown only 10 results in my
page.

How can I avoid to call the query twice ?

Bob
Jul 17 '05 #1
6 1699
rw
yust save result in session

Bob Bedford wrote:
I've a query quite important to execute.

I've to fill an array with all result, so the query is called once wich
returns all ID's

Then I call the same query a second time as I shown only 10 results in
my page.

How can I avoid to call the query twice ?

Bob


--
Robert Was
Jul 17 '05 #2

"rw" <rw***@gazeta.pl> a écrit dans le message de news:
cs**********@diplo.bci.pl...
yust save result in session


don't really understand what you mean!
should I
$_SESSION['queryresult'] = mysql_result('select...',$mydb); ???

and how to do next and previous then ? I will only know the next and
previous recordid in order to put a next and previous button with param
ID=previousID or ID=nextID

Bob
Jul 17 '05 #3
Bob Bedford wrote:
I've a query quite important to execute.

I've to fill an array with all result, so the query is called once wich
returns all ID's

Then I call the same query a second time as I shown only 10 results in my
page.

How can I avoid to call the query twice ?

Bob


Hi Bob,

you didn't mention if you want to use both results on the same page.
If so:
- Loop over ALL the results once.
- Then loop over the first 10

If you want the results to be available on another page, store them in a
session.

Regards,
Erwin Moller
Jul 17 '05 #4

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news: 41**********************@news.xs4all.nl...
Bob Bedford wrote:
I've a query quite important to execute.

I've to fill an array with all result, so the query is called once wich
returns all ID's

Then I call the same query a second time as I shown only 10 results in my
page.

How can I avoid to call the query twice ?

Bob


Hi Bob,

you didn't mention if you want to use both results on the same page.
If so:
- Loop over ALL the results once.
- Then loop over the first 10

If you want the results to be available on another page, store them in a
session.

I want 10 results (not necessarely the first 10) in the actual page. In the
other page, I need only 1 result BUT I've to know previous and next record.

Takes this example. I'm in the search page. The result gives 150 results. I
only show 10 results/page.
Now, I click on an element (one of the result). From there I'd like to click
on "next item" or "previous item".
For this I've to know each element of the query's result. But how to do
previous and next ??? now I've executed the query, then I put each element
ID in an array. When I go in element page, I have the array, so clicking on
previous I've the previous ID, clicking on next, I've the next ID. Then I
show the element with the new ID.
The problem is that If I click 12 times on "next", I've to know that
clicking on "return" button (not the previous of the browser), the page has
changed. I should be in page 2 now.
How to fill the array then show only 10 results ? What should I do ?

Bob
Jul 17 '05 #5
Bob Bedford wrote:
"Erwin Moller"
<si******************************************@spam yourself.com> a
écrit dans le message de news:
41**********************@news.xs4all.nl...
Bob Bedford wrote:
I've a query quite important to execute.

I've to fill an array with all result, so the query is called once
wich returns all ID's

Then I call the same query a second time as I shown only 10 results
in my page.

How can I avoid to call the query twice ?

Bob


Hi Bob,

you didn't mention if you want to use both results on the same page.
If so:
- Loop over ALL the results once.
- Then loop over the first 10

If you want the results to be available on another page, store them
in a session.

I want 10 results (not necessarely the first 10) in the actual page.
In the other page, I need only 1 result BUT I've to know previous and
next record.

Takes this example. I'm in the search page. The result gives 150
results. I only show 10 results/page.
Now, I click on an element (one of the result). From there I'd like
to click on "next item" or "previous item".
For this I've to know each element of the query's result. But how to
do previous and next ??? now I've executed the query, then I put each
element ID in an array. When I go in element page, I have the array,
so clicking on previous I've the previous ID, clicking on next, I've
the next ID. Then I show the element with the new ID.
The problem is that If I click 12 times on "next", I've to know that
clicking on "return" button (not the previous of the browser), the
page has changed. I should be in page 2 now.
How to fill the array then show only 10 results ? What should I do ?

Bob


Plenty of examples available from Google.

See this, for example:
http://phpclasses.mirrors.nyphp.org/...kage/2012.html

--
Virgil
Jul 17 '05 #6

"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> wrote in message
news:41**********************@news.sunrise.ch...
I want 10 results (not necessarely the first 10) in the actual page. In the other page, I need only 1 result BUT I've to know previous and next record.
Takes this example. I'm in the search page. The result gives 150 results. I only show 10 results/page.
Now, I click on an element (one of the result). From there I'd like to click on "next item" or "previous item".
For this I've to know each element of the query's result. But how to do
previous and next ??? now I've executed the query, then I put each element
ID in an array. When I go in element page, I have the array, so clicking on previous I've the previous ID, clicking on next, I've the next ID. Then I
show the element with the new ID.
The problem is that If I click 12 times on "next", I've to know that
clicking on "return" button (not the previous of the browser), the page has changed. I should be in page 2 now.
How to fill the array then show only 10 results ? What should I do ?


Hmmm. Tricky. In order to determine what the previous and next item are, you
will need to perform the original query. There's really no way around that.
Storing data in session variable is always rather dicey in these kinds of
scenarios.

What I would do is in the URL to the element page, put in the variables that
we'd need to reconstruct the search query, the id of the element, and the
position of that element within the result set. In the element page itself,
perform the same query, but use a window of 3--one ahead of the position of
the element and one behind. To make sure that the position of the element
within the result set hasn't since changed, compare the id of the middle row
to the one from the URL. If they don't match, retrieve the entire data set
to look for the correct 3 rows. For the "prev" and "next" links, go the same
thing.

The drawback is that running the query is slower than getting the data of
the element using a primary key. On the other hand, because you're running
the same query over and over, the database server should be smart enough to
cache that data set.
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christian | last post by:
HI, I have a function that is used to constrain a query: Select COl1, Col2 From MyTable WHERE col1 = ... AND col2 = ... And MyFunction(col1) = ... My problem is that MyFunction is executed...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
1
by: Alan J. Flavell | last post by:
What are the theoretical and practical limits on the length of a GET query string, currently? Strange to say, I found this rather simple question hard to answer, possibly because of searching...
1
by: David Barger | last post by:
Greetings, It appears that an Append Query I run in Access XP is randomly failing to append a field. I have payroll data being entered into a payroll database. This data is exported daily to...
4
by: serge | last post by:
I am running a query in SQL 2000 SP4, Windows 2000 Server that is not being shared with any other users or any sql connections users. The db involves a lot of tables, JOINs, LEFT JOINs, UNIONS...
6
by: Dixie | last post by:
I have asked this question before, but I could not get the suggested solution work. So I will give more details this time. I have an append query that adds several hundred records to a table...
10
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
8
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.