PHP 5.5 - Placing SQL Column Names Into Array ?

Started by
1 comment, last by RLS0812 10 years, 3 months ago

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";

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

Advertisement

Sorry, I don't have any PHP code to show, but you should try querying from the information_schema.columns table to get the column names. There is a query example at the bottom of the link.

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>";
         }
?>

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

This topic is closed to new replies.

Advertisement