mysql_num_fields用于获得查询结果的列数,如果执行成功返回列数,执行失败,返回boolean值
<?php $UserName = 'abc'; $Password = '1234'; $DbHandle = mysql_connect ('localhost', $UserName, $Password); if (!$DbHandle) { die 'No database connection could be established.'; } $DBName = 'w3db; if (!mysql_select_db ($DBName, $DbHandle)) { die 'Database could not be selected.'; } $Query = "SELECT ISBN, Title, Author FROM articles"; $articles = mysql_query ($Query, $DbHandle)); $RowCount = mysql_num_rows ($articles); $FieldCount = mysql_num_fields ($articles); $I = 0; while ($I < $RowCount) { $Row = mysql_fetch_assoc ($articles); echo "Row $I<br />\n"; $J = 0; while ($J < $FieldCount) { echo "$Row[$J]<br />\n"; ++$J; } ++$I; } mysql_close ($DbHandle); ?>