Return to Snippet

Revision: 43155
at March 18, 2011 01:34 by erraja_07


Initial Code
mysql_connect("localhost", "root",'root') or die();
mysql_select_db('itemtest') or die();

$query = "SELECT * FROM itemmasterlist WHERE 1";

$result = mysql_query($query);

$numfields = mysql_num_fields($result);
$row = 0;

for($i=0; $i < $numfields; $i++){
    if(mysql_result($result, $row, $i) != ''){
        $name[$count] = mysql_field_name($result, $i);
        $count++;
    }
    
}

echo 'num of fields filled : '.$count.'<br />';
for($i=0; $i< count($name); $i++){
    echo 'field : '. $name[$i]. ' is not empty<br />';
}

Initial URL
http://www.webdeveloper.com/forum/showthread.php?t=171879

Initial Description

                                

Initial Title
PHP get mysql table column count

Initial Tags

                                

Initial Language
PHP