开发者

how to query to display column names except an array list

开发者 https://www.devze.com 2023-01-04 14:13 出处:网络
hey guys im looking for to show columns of a tableexcept some.forexample my table name mobile_table has columns like :

hey guys im looking for to show columns of a table except some. forexample my table name mobile_table has columns like :

  • sony
  • nokia
  • apple
  • LG
  • Sumsung

...and i need to sho开发者_StackOverflow中文版w these columns except Sumsung ,LG

$exceptions_arr = "LG,Sumsung"

i know how to show column names of a table but not to apply exeption array filter !

$query = "SHOW COLUMNS FROM mobile_table"; 
$result = mysql_query($query); 

while($columns = mysql_fetch_array($result, MSQL_ASSOC)) 
{ 
  echo $columns;     
}


$exceptions_arr = array("LG",
                        "Sumsung"
                       );

while($columns = mysql_fetch_array($result, MSQL_ASSOC)) {  
   foreach($columns as $columnName => $columnValue)
   if (!in_array($columnName,$exceptions_arr)) {
      echo $columnValue; 
   }
}

Alternatively, select only the columns that you want rather than every column and then remove those you don't want


It really doesn't look like normalized table.
I recommend reading about normalization:
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
http://mysqldump.azundris.com/archives/20-Nermalisation.html
http://www.keithjbrown.co.uk/vworks/mysql/

0

精彩评论

暂无评论...
验证码 换一张
取 消