I'm trying to figure out how best to get this PHP statement
$wpdb->get_results("SELECT verb, display_name AS organization, inline_the FROM
userorganizations U, organizations O WHERE U.org_id = O.ID AND
U.user_id=$author_id", OBJECT);
To spit out something like the following:
John开发者_C百科 works for Initech, owns John's Tasty Pastry, and writes for the New York Times
I can do almost everything except figure out a good way to insert the bolded "and" up above: I don't know how to iterate through to just before the final row, do something special, then run the final row.
By default, get_results()
returns a numerically indexed object of the results. It's easy to figure out how many results you have by assigning that object to a variable and then using count()
to figure out how many results you have.
So:
$results = $wpdb->get_results(..., OBJECT);
foreach($results as $result) {
if($result == $results[count($results) - 1]) echo '<strong>and</strong>';
... The rest of your loop here ...
}
精彩评论