2010-10-11 28 views
0

我試圖找出如何最好地得到這個PHP語句在PHP/WordPress的創建可讀的列表輸出

$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); 

吐出類似如下:

約翰工程Initech的,擁有約翰的美味糕點,經常爲紐約時報

我幾乎可以做一切,除了搞清楚一展身手插入粗體的方式「和」上面:我不知道如何迭代到最後一行之前,做一些特別的事情,然後運行最後一行。

回答

0

默認情況下,get_results()返回結果的數字索引對象。通過將該對象分配給一個變量,然後使用count()來計算出您有多少結果,可以很容易地計算出您有多少結果。

所以:

$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 ... 
}