473,386 Members | 1,867 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.

duplicating mysql_query result

Hi is there a way of duplicating the same mysql_query resource result
or is there a way to stop it from being cleared once it is no longer
needed? I need to run a ... while(mysql_fetch_array($result)) ... loop
twice and I want to avoid re-runnuing the query.
Cheers,
Ciarán

Mar 27 '07 #1
2 1422
Ciaran wrote:
Hi is there a way of duplicating the same mysql_query resource result
or is there a way to stop it from being cleared once it is no longer
needed? I need to run a ... while(mysql_fetch_array($result)) ... loop
twice and I want to avoid re-runnuing the query.
Sure thing, just use the mysql_data_seek() function between the while()
loops, like this:

while($rowdata = mysql_fetch_array($result)) {
// do something
}
mysql_data_seek($result, 0);
while($rowdata = mysql_fetch_array($result)) {
// do something entirely different
}

http://php.net/mysql_data_seek

--
Kim André Akerĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Mar 27 '07 #2
On Mar 27, 3:42 pm, Kim André Akerĝ <kiman...@NOSPAMbetadome.com>
wrote:
Ciaran wrote:
Hi is there a way of duplicating the same mysql_query resource result
or is there a way to stop it from being cleared once it is no longer
needed? I need to run a ... while(mysql_fetch_array($result)) ... loop
twice and I want to avoid re-runnuing the query.

Sure thing, just use the mysql_data_seek() function between the while()
loops, like this:

while($rowdata = mysql_fetch_array($result)) {
// do something}

mysql_data_seek($result, 0);
while($rowdata = mysql_fetch_array($result)) {
// do something entirely different

}
Fantastic! Thanks a lot!
Ciarán

Mar 27 '07 #3

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

Similar topics

0
by: Patrick H. E. Foubet | last post by:
Hi all, I would like to suggest you some refelxion about this : I run this simple code : .... $res = mysql_query ($requete, $connexion) or die(mysql_error()); while (is_object($elt = ...
0
by: abu | last post by:
I'm having a problem with Fast Template duplicating the content. Here's the code, hoping someone may be of help, thanks! while(list($last_name)=mysql_fetch_array($data1)) { $data2 =...
1
by: Johan den Boer | last post by:
Hi, Sometimes I see this piece of code $result = @mysql_query( $query ) or $result = mysql_query( $query ) What is the use of the '@' character ? regards Johan
4
by: Bruce A. Julseth | last post by:
I know the following $sql will fail since there is no Customer='Smith'. I want to determine how to test a failure of mysql_query. I thought mysql_query returned false if a query failed. The test...
5
by: lkrubner | last post by:
www.php.net says: >>>>>>>>>>>> Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier or FALSE if the query was not executed correctly. For other type of...
7
by: John Moore | last post by:
Hi I posted three days ago about a function I wrote which kept refusing to run a mysql_query. Well I did away with the function, and hard coded the variables into the query itself. Here's...
2
by: techjohnny | last post by:
Error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 Warning: mysql_num_rows(): supplied argument is...
4
by: atyndall | last post by:
OK, this is the relevant portion script: <?php $username = '__'; // MySQL Database Username. $password = '__'; // MySQL Database Password. $server = '__'; // MySQL Database server (most...
9
by: JRough | last post by:
I tried to pass the $result from a mysql_query in a url like this line Header("Location:clm_historyXL.php?_result=".$result); but on the redirect location clm_history.php page I get an error on...
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: 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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.