2010-02-02 89 views
0

我有这个代码在wordpress网站,在自定义表。该网页是在这里: http://ulsandbox.org/bbtb10/?page_id=183WordPress的自定义表循环不太正确

<h1> 2009 Authors List</h1> 
<h3> Click on each author to read more about them</h3> 
<p>&nbsp;</p> 
<hr align="left" width="75%"> 
View Categories:<p><a href="#childrens">Childrens</a> | <a href="#fiction">Fiction</a> | <a href="#non-fiction">Non-Fiction</a> | <a href="#teen">Teen</a> | <a href="#other">Other</a></p> 
<p>&nbsp;</p> 

<?php 

$results = $wpdb->get_results('SELECT author_sub9.Sid, author_sub9.author_lname, author_sub9.author_fname, author_sub9.title, author_sub9.genre, author_sub9.approved 
FROM author_sub9 
WHERE author_sub9.approved = 1 
ORDER BY author_sub9.genre,author_sub9.author_lname', ARRAY_A); 
$sLastGenre=''; 
if ($results) { 
foreach ($results as $Row) 
    if ($Row['genre']!=$sLastGenre) 
    { 
    if ($sLastGenre != '') 
echo '<br /><a href="authordetail.php?recordID='.$Row['Sid'].'">'.$Row['author_lname'].'</a>'.','.$Row['author_fname'].'<br />'; 
    $sLastGenre=$Row['genre']; 
    } 

} 



?> 

正如你看到的,我得到:

Fatal error: Call to a member function get_results() on a non-object 

回答

0

您已经添加WPDB $作为一个全球性的?

global $wpdb; 

$wpdb->get_result($sql, ARRAY_A); 
+0

Hmnn,这有助于消除错误... http://ulsandbox.org/bbtb10/?page_id=183 而我得到的结果,但我想我的心不是循环吗? 它应该看起来像这样: http://booksbythebanks.org/authors09.php – LisaH 2010-02-02 17:27:18