Sign in to follow this  
RLS0812

PHP 5.5 - Placing SQL Column Names Into Array ?

Recommended Posts

RLS0812    3043

 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
RLS0812    3043

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

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