I would strongly recommend looking into the PHP docs on a function to see how it operates. This doc page should help you digest and understand what it actually does.
In Summary
In short what you have used as an example will take $result
, which is a myqsli_query()
result and create an object for the current row.
The while
loop is in place to loop through the entire query results. In turn, this creates an object (under the same variable $obj
) for every row.
One example extracted from the docs:
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($obj = mysqli_fetch_object($result)) {
printf ("%s (%s)
", $obj->Name, $obj->CountryCode);
}
/* free result set */
mysqli_free_result($result);
}
Returning, for example
Pueblo (USA)
Arvada (USA)
Cape Coral (USA)
Green Bay (USA)
Santa Clara (USA)
P.S. If you use Sublime Text, this plugin is marvelous in jumping to the docs: https://github.com/kemayo/sublime-text-2-goto-documentation