473,486 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

multiple mysql_fetch_array() calls

Hi All,
I've got a simple query hopefully somebody can clear up for me. I need to
make a query on a database to select a set of table rows, using something
like:

$result = mysql_query($query);

I can then use mysql_fetch_array in a while loop to access each row in the
result. This all works fine.

However, what I'd like to do is to go through this result more than once.
ie. use mysql_fetch_array() to go through each row in $result more than
once. How do I do this?. There appears to be no my of resetting
mysql_fetch_array back to the beginning of the $result once all rows have
been erad once.

I don't want to make multiple identical queries on the database, simply to
read the same information.

Any ideas?.

Ta,
Dave
Jul 17 '05 #1
2 6085
Dave Moore wrote:
Hi All,
I've got a simple query hopefully somebody can clear up for me. I need to
make a query on a database to select a set of table rows, using something
like:

$result = mysql_query($query);

I can then use mysql_fetch_array in a while loop to access each row in the
result. This all works fine.

However, what I'd like to do is to go through this result more than once.
ie. use mysql_fetch_array() to go through each row in $result more than
once. How do I do this?. There appears to be no my of resetting
mysql_fetch_array back to the beginning of the $result once all rows have
been erad once.

I don't want to make multiple identical queries on the database, simply to
read the same information.

Any ideas?.

Ta,
Dave

Store your first time result in your own query.. and then just loop your
own query as many times as needed...

$yourArray = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC) {
$yourArray[] = $row;
}

then just do this as many times as needed...

foreach($yourArray as $rowNum => $row) {
//$row would be same as the original $row inside the while loop
inside this loop.
}
Jul 17 '05 #2
You can also use this:

mysql_data_seek ($result, 0);
http://us4.php.net/manual/en/functio...-data-seek.php

Jul 17 '05 #3

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

Similar topics

1
4082
by: bill | last post by:
Hi, This looks like a simple problem, but I just can't seem to wrap my head around it. I'm trying to build a table dynamically, based on a result set from mysql. There will be 9 results for a...
15
2648
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
0
1200
by: LS | last post by:
1. When I select an assignment, the class roster disappears. I don't want it to show up until I select an assignment. 2. I want to be able to enter grades and submit all with only one submit...
1
1381
by: LS | last post by:
1. When I select an assignment, the class roster disappears. I don't want it to show up until I select an assignment. 2. I want to be able to enter grades and submit all with only one submit...
2
3629
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
1
5862
by: abhishekhs | last post by:
Hi all I have more than one multiple select lists in a page. Something like this <tr> <td> <select NAME="StrainList" ID="StrainList" SIZE="5" multiple="multiple" style="width: 150px"> <?...
1
2894
by: quill | last post by:
Hi I am making a chatroom script and it appears that the problem seems to be that my setTimeout's are conflicting. The logic is as follows: Run a login check every x seconds Run a trigger...
2
1917
by: dylanhughes | last post by:
I'm looking for an example of a login system that has multiple fields (2 to be exact) + password. e.g username, company name and password, the user, company and password are checked against a mysql...
8
7233
by: obtrs | last post by:
show data of multiple tables? i have 3 tables i want to show the data from them to a page. table1 "trip" table2 "seat" table3 "user_information" show all the data of table one which is...
0
7123
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,...
0
7175
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...
0
5430
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,...
1
4864
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...
0
4559
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...
0
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
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...

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.