469,306 Members | 1,748 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

printing out array keys

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
4 13520
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
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
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
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.

Similar topics

1 post views Thread by waisty vb.net rookie | last post: by
7 posts views Thread by Magnus Warker | last post: by
4 posts views Thread by Arif | last post: by
7 posts views Thread by pauld | last post: by
6 posts views Thread by routeslip | last post: by
3 posts views Thread by Mike P | last post: by
2 posts views Thread by Sjoerd | last post: by
6 posts views Thread by tedpottel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.