Jump to content
  • Advertisement
Sign in to follow this  
RLS0812

PHP 5.5 - Placing SQL Column Names Into Array ?

This topic is 1608 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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!