mysql_fetch_field

I’m having problems using mysql_fetch_field(), more to the point it’s returning nothing. The mysql_fetch_assoc() works fine. Is there something I need to set in MySQL in order to use mysql_fetch_field()?

[php]
$conn = mysql_connect( $host, $user, $password );
mysql_select_db( $database, $conn ) or die(mysql_error());
$sql = “SELECT artist, album FROM music”;

$result = mysql_query( $sql, $conn ) or die(mysql_error());

//while( $field = mysql_fetch_assoc( $result ))
while( $field = mysql_fetch_field( $result ))
{

print “<tr style=“background-color: white”>”;
//print “

” . $field[‘artist’] . “”;
//print “” . $field[‘album’] . “”;

if( isset( $field->artist )) {
print “

” . $field->artist . “”;
} else {
print " Not Set ";
}
if( isset( $field->album )) {
print “” . $field->album . “”;
} else {
print " Not Set ";
}

//print “

” . $field->artist . “”;
//print “” . $field->album . “”;
print “”;
}
[/php]

if mysql_fetch_assoc works why not just use that? Personally i’ve never used fetch field as i usually just use mysql_result for the way I code.

I’m trying to learn PHP, so I wanna know how to use mysql_fetch_field(). I’ll never learn if I can use another function.

Sponsor our Newsletter | Privacy Policy | Terms of Service