I am a fairly new PHP programmer so forgive me if this is elementary.
I need to use an array with multiple results from a query more than once on the same page, but I can't seem to find out how to go back to the first result and display the result again. I've looked all over and I'm just stuck.
reusing resource results
Moderator: General Moderators
...
If I understood corectly:
First construct an empty array.
When you query the database - you need to add each result to the array.
Then that array ( can be multi-dimensional for more data storage ) members can be called when ever you need them - to show their contents (numerous times ) on the page.
Is this what you meant.
First construct an empty array.
When you query the database - you need to add each result to the array.
Then that array ( can be multi-dimensional for more data storage ) members can be called when ever you need them - to show their contents (numerous times ) on the page.
Is this what you meant.
-
jstratman33
- Forum Newbie
- Posts: 3
- Joined: Sat Jan 15, 2005 11:27 pm
OK, let's try this. Here's basically what I have set up.
Now, when I try to list the results again in another FOR loop, all I get is a NULL value. How do I get back to the first row of the result?
Code: Select all
$query = "SELECT * FROM members WHERE state = 'NY' ORDER BY last_name";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
for ($i=0; $i<$num_rows; $i++) {
$row = mysql_fetch_array($result);
echo '<b>'.$rowї'last_name'].', '.$rowї'first_name'].'</b><br>';
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
mysql_data_seek(), however.. caching the data into an array is preferrable, but may consume a large amount of memory.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA