Getting One Value from a multidemensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Getting One Value from a multidemensional array

Post by Anarking »

Good evening ladies and gentlemen


Im writing a script that needs to get the names of each column from a sql table

Currently I have this

$qColumnNames = mysql_query("SHOW COLUMNS FROM sometable",$link) or die("mysql error");
$numColumns = mysql_num_rows($qColumnNames);
echo "

";
while ($row = mysql_fetch_assoc($qColumnNames)) {
print_r($row);
}
echo "

";

Which gives me thi output

Array
(
[Field] => id
[Type] => int(10) unsigned
[Null] => NO
[Key] => PRI
[Default] =>
[Extra] => auto_increment
)
Array
(
[Field] => Yes
[Type] => text
[Null] => NO
[Key] =>
[Default] =>
[Extra] =>
)
Array
(
[Field] => No
[Type] => text
[Null] => NO
[Key] =>
[Default] =>
[Extra] =>
)
Array
(
[Field] => maybe
[Type] => text
[Null] => NO
[Key] =>
[Default] =>
[Extra] =>
)
Array
(
[Field] => who_care
[Type] => text
[Null] => NO
[Key] =>
[Default] =>
[Extra] =>
)


What I want to do is take each value of [Field] and add that to a new array, Can anyone show me how to do that?

Thanks.
user333
Forum Newbie
Posts: 8
Joined: Tue Mar 03, 2009 12:02 pm

Re: Getting One Value from a multidemensional array

Post by user333 »

Code: Select all

 
//Initiate an array
$fieldsArr = array();
while ($row = mysql_fetch_assoc($qColumnNames)) {
   $fieldsArr[] = $row['Field'];
}
 
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Re: Getting One Value from a multidemensional array

Post by Anarking »

ahhhh


Much thanks my brother.
Post Reply