By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

printing out array keys

P: n/a
i'm trying to find a simple way of printing out the keys in an array
generated by mysql_fetch_array which returns a single row.

i.e.

while ($row=mysql_fetch_array($result) )
{

print out the $row keys and values

}

is this possible?

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
kaptain kernel (63.885% quality rating):

print out the $row keys and values

is this possible?


print_r ?

/joe
--
Jordan kisses a muff from git.talk.flame in the Earl. Sixth Street is
plus-cute in Smyrna!! In El Myr, Taco Bell is elementary. Alpharetta is
swell.
Jul 17 '05 #2

P: n/a
kaptain kernel wrote:
i'm trying to find a simple way of printing out the keys in an array
generated by mysql_fetch_array which returns a single row.

i.e.

while ($row=mysql_fetch_array($result) )
{

### print out the $row keys and values
foreach ($row as $k=>$v) {
echo "row[$k] = $v<br/>\n";
}

}

is this possible?


With mysql_fetch_array() you'll get both numeric and column names
indices. I only use mysql_fetch_row() for numeric indices and
mysql_fetch_assoc() for column names indices.
HTH

--
..sig
Jul 17 '05 #3

P: n/a
kaptain kernel wrote:
i'm trying to find a simple way of printing out the keys in an array
generated by mysql_fetch_array which returns a single row.


$query = "SELECT * FROM table WHERE `key`='value' LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_array($result,MYSQL_ASSOC);

foreach($row as $key => $value) {
echo "key: $key , value: $value <br>";
}

HTH

--
Suni
Jul 17 '05 #4

P: n/a
thanks - the foreach key=>value construct is exactly what i'm looking
for.....

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.