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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array question

Status
Not open for further replies.

ScottCybak

Programmer
Sep 29, 2000
48
CA
Hi, i'm trying to cycle through an array of query results. The query has 4 fields

$Sql = "SELECT.. blah blah ";
$Result = mysql_query($Sql);
$Rst = mysql_fetch_array($Result);

Now, i know i can cycle through the rst on the fly using a While (x = fetch_array blah blah) BUT, i want to do this afterwards

Normally, i reference it while i'm looping via $Rst['fieldName'] BUT, i can't figure out how to reference it while i'm in a foreach loop..

basically, i want to say:

foreach ($Rst['fieldName'] as $x) {
echo $x;
}

but am unsure of syntax. TIA! Scott Cybak
scott@athree.com
 
Probably something like:
foreach($rst as $key=>$value)
{
echo &quot;$key $value<br>\n&quot;;
}

That should probably do the trick for you if I understand what you are trying to do properly.
 
Jim,

Thanks for the response. Seeing what you had done and testing made me realize i was approaching the situation wrong. I was only getting the result from the 1st row because i never knew that mysql_fetch_Array grabs only a single row of the query results.

Thanks for opening my eyes! Scott Cybak
scott@athree.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top