mysql_fetch_object()
object mysql_fetch_object(result)This function returns a row of data as an object from the results set given. The function returns false if there are no more rows to return. The field names of the results set are used to retrieve data from the object returned. Here is an example:
...
$sql_stmnt = "SELECT count(wrid) AS wr_count, client_name
FROM workreq, clients
WHERE status <> 'done'
AND workreq.clientid = clients.clientid
GROUP BY workreq.clientid
ORDER BY wr_count DESC";
$results = mysql_query($sql_stmnt);
while($row = mysql_fetch_object($results)) {
print $row->client_name . " " . $row->wr_count . "\n";
}
...This script is written to generate a list of clients that have
outstanding work requests and to give a count of the number of
requests for each, in descending order. Within the
while statement that follows, each row of the
results set is processed with
mysql_fetch_object(). The value of each
element of the object created for each row is displayed by calls using
the field names, not the column names. For instance, to get the data
from the field with the number of work requests, you use the
wr_count alias. Here are a few lines from the
output of this script:
... Bracey Logistics 3 Neumeyer Consultants 2 Farber Investments 4