用户评论:

[#1]

php at jezusisheer dot nl [2007-03-29 23:10:22]

Note that, if you want to get the amount of columns of a table and you're using the "SHOW COLUMNS FROM $table" query, you will have to use mysql_num_rows() instead of mysql_num_fields() on the result. This becomes logical when thinking about it, because the SHOW COLUMNS query returns a result with six columns (Field, Type, Null, Key, Default and Extra) and with a single row for every column found. If you'd count the number of fields, you'd always get 6. If you count the number of rows, you'll get the amount of columns found.

[#2]

tharkey at tharkey dot net [2003-06-19 11:26:15]

You can use it without a requete, just to list the fields :

$liste_champs = mysql_list_fields ( $Base, $Table, $connexion);

for ($i=0; $i

echo ( mysql_field_name ($l_champs, $i) );

echo (' / ');

}

[#3]

apass AT passmoore DOT com [2002-10-01 15:52:49]

Adding to the last comment: you can dynamically loop through any number of  columns AND rows like so-

$query="your SQL";

$result=mysql_query($query) or die("Query ($query) sucks!");

$fields=mysql_num_fields($result);

echo "

for ($i=0; $i

{ print "

".mysql_field_name($result, $i).""; }

echo "

\n";

while ($row = mysql_fetch_row($result)) { //Table body

echo "

";

for ($f=0; $f

echo "

$row[$f]"; }

echo "

\n";}

echo "

";

This has been tested.

[#4]

matt at iwdt dot net [2001-09-23 18:09:28]

here's one way to print out a row of

tags from a table

NOTE: i didn't test this

$result = mysql_query("select * from table");

for ($i = 0; $i

print "

".mysql_field_name($result, $i)."\n";

}

post a comment if there's an error

[#5]

bwark at stanford dot edu [2000-12-24 02:56:35]

If you just want the number of fields in a table, you can do something like this:

$db_id=mysql_connet();$result=mysql_query("DESCRIBE [tableName],$db_id);$numFields= mysql_num_rows($result);

?>

Because "DESCRIBE" returns one row for each field in the table (at least in MySQL), this will work.

mysql_num_fielfs_mysql_num_fields相关推荐

最新文章

  1. 【Qt】Qt再学习(七):QLocalServer、QLocalSocket
  2. HDU 3336 Count the string(KMP+DP)
  3. 【django轻量级框架】Django框架介绍与安装
  4. iOS 合并.a文件,制作通用静态库
  5. 标准的JS里,eval和window.eval属于不同的语法!
  6. 华为主题锁屏壁纸换不掉_快来看看华为与荣耀手机的这16款主题!别一直用系统默认主题啦!...
  7. ADO.NET Entity Framework Extensions 简单应用
  8. VI3的VLAN配置:VST、EST和VGT标记
  9. MVC3.0图片滚动和相册展示(下)
  10. PAT 乙级 1014. 福尔摩斯的约会 (20) Java版
  11. 老妈~老妈~我爱你~~~~~~~阿弥陀佛保佑你~~~~~~~
  12. HDU-2057(16进制的输入输出)
  13. 视频素材网站,免费可商用
  14. Jenkins远程命令执行漏洞(CVE-2018-1000861)
  15. python把数据生成图表_python从Oracle读取数据生成图表
  16. 从零到一学爬虫-爬取微博热搜示例
  17. 使用网址--java JPI代码示例
  18. 有声语音计算机软件,有声语音计算器
  19. testNG接口自动化测试干货分享
  20. Python基础--魔法方法()运算符重载)

热门文章

  1. 数据结构与算法的分析 —— 渐进复杂度(三个记号)
  2. 深度学习实践指南(四)—— 一个典型的深度学习的实践流程
  3. Tricks(三十八)—— 在不计算欧式距离的前提下判断点到两点的距离哪个更近
  4. bootstraptable获取所有数据_关于Redis中的五种数据结构,要知其然知其所以然
  5. 怎么自学python-如何系统地自学 Python?
  6. python工资这么高为什么不学-现在Python就业薪资高吗?
  7. python程序-Python程序执行原理,python程序怎么运行的?
  8. 自学python好找工作么-Python就业前景如何?培训后好找工作吗?
  9. python入门指南 许半仙txt-影帝的脑子坏了
  10. Unity VR开发出语音识别功能