PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_num_fields() function in PHP


Tutorials »Php »

Topic

What is mysql_num_fields() function in PHP?
How does mysql_num_fields() works?




Explanation

This mysql_num_fields() function in php gets number of fields in result set.

Syntax
int mysql_num_fields ( resource result)

Returns number of fields in result on success, or NULL on error.

mysql_num_fields() function returns the number of fields in the recordset returned by mysql_query operation.

Example


<?php

//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

//select database
mysql_select_db("database", $link);

//execute simple query
$sql = mysql_query("SELECT * FROM table1", $link);
$result = mysql_query($sql,$link);

//Fetch number of fields in the result set
$fields=mysql_num_fields($result);

//print number of fields in the result set
echo"No of fields: ".$fields;

//Close connection
mysql_close($link);
?>



In the above code the result of mysql_query() result set is passed to mysql_num_fields() function to retrieve the count of fields present in the recordset returned by mysql_query function.

RESULT:

No of fields:12


See also:





Other Links

web hosting