Sign in to follow this  

PHP 5.5 - Placing SQL Column Names Into Array ?

This topic is 1446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 I have been looking all over the place for how to dump all the column names in a SQL table into a PHP array. Unfortunately all the information I have dug up no longer works with PHP 5.5 ( depreciated ) .

 

 Does any one have a WORKING code example that can grab all the column names and dump into an array in PHP ?

$sql = mysqli_connect("127.0.0.1","root","","players"); 
$table = "info";

Share this post


Link to post
Share on other sites

After a couple hours of guessing, here is the solution I came up with for my problem:

<?php
$sql = mysqli_connect("127.0.0.1","root","","players"); 
$table = "info";

$get = mysqli_query($sql, "SHOW COLUMNS FROM " . $table);
while ($col = mysqli_fetch_row($get)) {
     echo "Existing column: " .$col[0] . "<br>";
         }
?>

Share this post


Link to post
Share on other sites

This topic is 1446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this