Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to reuse mysql query result that has been fetched from php mysql_fetch_array()?

Posted on 2008-10-09
3
1,534 Views
Last Modified: 2013-12-12
Is there anyone know how to reuse mysql query data that was fetched from php using mysql_fetch_array function?

For example:
//query my query statement
$query = mysql_query ("SELECT * FROM sample_table");

// So at here using while loop to populate the query result
while ($result = mysql_fetch_array($query))
{
 echo $result[0]; // for example to display only first column
}

When running the code as above, record would be displayed. However if I were to fetch again the data for example:

//query my query statement
$query = mysql_query ("SELECT * FROM sample_table");

// So at here using while loop to populate the query result
while ($result = mysql_fetch_array($query))
{
 echo $result[0]; // for example to display only first column
}

//after the first while loop, i loop again and no record returned
while ($result1 = mysql_fetch_array($query))
{
echo $result1[0];
}


0
Comment
Question by:encus
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 20 total points
ID: 22684977
//query my query statement
$query = mysql_query ("SELECT * FROM sample_table");

// So at here using while loop to populate the query result
while ($result = mysql_fetch_array($query))
{
 echo $result[0]; // for example to display only first column
}

mysql_data_seek($query,0);

//after the first while loop, i loop again and no record returned
while ($result1 = mysql_fetch_array($query))
{
echo $result1[0];
}

>> encus, Premium Service Member
FYI: as a premium service member you have unlimited points. You will most likely get more timely responses if you are more generous
0
 

Author Closing Comment

by:encus
ID: 31504919
thx for your fast response
0
 
LVL 82

Expert Comment

by:hielo
ID: 22685994
you are welcome.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question