473,722 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1708
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.p l> a écrit dans le message de news:
cs**********@di plo.bci.pl...
yust save result in session


don't really understand what you mean!
should I
$_SESSION['queryresult'] = mysql_result('s elect...',$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************ *************** *************** @spamyourself.c om> 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************ *************** *************** @spamyourself.c om> 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******@YouKn owWhatToDoHereh otmail.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
14675
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 as many times that there are
8
89312
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 tblMyTable.UniqueID = tblMyTableTEMP.UniqueID SET tblMyTable.myField = tblMyTableTEMP.myField, tblMyTable.myField2 = tblMyTableTEMP.myField2,
1
6354
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 the wrong terms, or, rather, because the terms ("get", "form", "length" etc.) are so common as to be useless for searching. An email correspondent assures me that there's an RFC which limits the length of a URI, including query string, to 1024...
1
2481
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 two csv files. (One for updated data, and the other for unupdated data.) The CSV files are attached to my Jobcosting database. After the CSV
4
3556
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 etc... Ok it's not a pretty code and my job is to make it better. But for now one thing I would like to understand with your help is why the same SP on the same server and everything the same without me changing anything at all in terms of SQL...
6
5016
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 into a text field. Next to this text field is a separate Number (Single) field with a unique ID number for the entry. I want each number to be 1 more than the previous entry's number to keep it unique (I don't want autonumbering for this, as I...
10
2643
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 relating to a separate table of locations). 3: details
12
3536
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 print the report three times, but do not know how
8
5917
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.. So if the user selects 3 months in the criteria form, there will be 3 (month) column headings, if he selects 6 months, the will be 6 headings.
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.