Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-09
3
Medium Priority
?
1,628 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
[X]
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
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 80 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …
Suggested Courses

604 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