Solved

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

Posted on 2008-10-09
3
1,520 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 …

776 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