Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

The mysql_field_seek function moves the internal field pointer to the specified field.
The next call to mysql_fetch_field will get information from this field. See
mysql_list_fields for an example of use.


<?
//connect to server as freetrade user, no password
$dbLink = mysql_pconnect("localhost", "freetrade", "");


//select the 'freetrade' database
mysql_select_db("freetrade", $dbLink);


//get everything from address table
$Query = "SELECT * ".
"FROM address ";
$dbResult = mysql_query($Query, $dbLink);


//skip to second field
mysql_field_seek($dbResult, 1);


//get description of each field
while($Field = mysql_fetch_field($dbResult))
{
print($Field->table, $Field->name, $Field->type
\N");
}
?>


string mysql_field_table(integer result, integer field)


The mysql_field_table function returns the name of the table for the specified field. If
an alias is used, as in the example below, the alias is returned.


<?
//connect to server as freetrade user, no password
$dbLink = mysql_pconnect("localhost", "freetrade", "");


//select the 'freetrade' database
mysql_select_db("freetrade", $dbLink);


//get everything from user table
//get everything from address table
$Query = "SELECT * ".
"FROM address a, user u ".
"WHERE u.Address = a.ID ";
$dbResult = mysql_query($Query, $dbLink);


$Fields = mysql_num_fields($dbResult);
for($i = 0; $i $Fields; $i++)
{
print(mysql_field_table($dbResult, $i). "
\n");
}
?>

Free download pdf