PHP get mysql table column count


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. mysql_connect("localhost", "root",'root') or die();
  2. mysql_select_db('itemtest') or die();
  3.  
  4. $query = "SELECT * FROM itemmasterlist WHERE 1";
  5.  
  6. $result = mysql_query($query);
  7.  
  8. $numfields = mysql_num_fields($result);
  9. $row = 0;
  10.  
  11. for($i=0; $i < $numfields; $i++){
  12. if(mysql_result($result, $row, $i) != ''){
  13. $name[$count] = mysql_field_name($result, $i);
  14. $count++;
  15. }
  16.  
  17. }
  18.  
  19. echo 'num of fields filled : '.$count.'<br />';
  20. for($i=0; $i< count($name); $i++){
  21. echo 'field : '. $name[$i]. ' is not empty<br />';
  22. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.