0

I have a mysql table with columns: Date, Jack, John, Amy. I want to show the column names (only the names!) in an array using php.

So the result should be an array like this:

$array = array('Date', 'Jack', 'John', 'Amy');

So when I do echo $array[1]; for example, the output should be 'Jack'.

Any help would be very appreciated.

3
  • if colomns names are there then you need right!!!!!!! Commented Feb 2, 2015 at 9:01
  • EXPLAIN tablename ... can be a solution Commented Feb 2, 2015 at 9:01
  • possible duplicate of Get Only column names as in array mysql Commented Feb 2, 2015 at 9:02

1 Answer 1

1

Use this code

$table_column = mysql_query("SHOW COLUMNS FROM YourTableName"); 
$tableArr = array();
while($row1 = mysql_fetch_assoc($table_column))
{
    $tableArr[] = $row1['Field'];
}

echo "<pre>";
print_r($tableArr);
Sign up to request clarification or add additional context in comments.

1 Comment

how do i display it in an array then?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.