Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to put recordset into array

Status
Not open for further replies.

cfsponge

Programmer
Feb 22, 2006
44
US
I wish to output a recordset into an array, so that I can sort all the results by a particular key. Right now, I have a while loop executing mysql_fetch_assoc(), but do not know how to get the 3 tablefields I'm retrieving into said query without making each field have an individual array, then trying to merge them.
 
Try a bidimensional array.
You have the ID field, and then you have the 3 fields you want for that ID.

Code:
$row=mysql_fetch_assoc($res);
myarray[$id]['field1']=$row['field1]
myarray[$id]['field2']=$row['field2'];
myarray[$id]['field3']=$row['field3'];

Although I should say, all sorting should be done at query level. With the Order by or group by clauses in your SQL statement.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top