Solved

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

Posted on 2008-10-09
3
1,490 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
Comment Utility
//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
Comment Utility
thx for your fast response
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
you are welcome.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now