Connecting Tech Pros Worldwide Forums | Help | Site Map

printing out array keys

kaptain kernel
Guest
 
Posts: n/a
#1: Jul 17 '05
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?

Disco Plumber
Guest
 
Posts: n/a
#2: Jul 17 '05

re: printing out array keys


kaptain kernel (63.885% quality rating):[color=blue]
>
> print out the $row keys and values
>
> is this possible?[/color]

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.
Pedro Graca
Guest
 
Posts: n/a
#3: Jul 17 '05

re: printing out array keys


kaptain kernel wrote:[color=blue]
> 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[/color]

foreach ($row as $k=>$v) {
echo "row[$k] = $v<br/>\n";
}

[color=blue]
> }
>
> is this possible?
>[/color]

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
Juha Suni
Guest
 
Posts: n/a
#4: Jul 17 '05

re: printing out array keys


kaptain kernel wrote:[color=blue]
> 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.
>[/color]

$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
kaptain kernel
Guest
 
Posts: n/a
#5: Jul 17 '05

re: printing out array keys


thanks - the foreach key=>value construct is exactly what i'm looking
for.....

Closed Thread