2009-12-11 98 views
-1

寻找一些帮助下面的代码。我认为可能存在与我组织php调用和函数调用的方式有关的问题。我是一名初学者,并试图让用户显示来自不同表格的结果,具体取决于他们点击的链接。PHP - 根据链接显示结果

我得到这个错误:

解析错误:语法错误,意外 '{' 在/home/content/c/e/l/celebrything/html/wp-content/themes/celebrything/sidebar.php在线16

任何帮助纠正这个问题将是惊人的。下面的代码:在第一if块上

<div id="sidebar"> 

<div class="post"> 
<h2> 

<font color="#333333">Most Popular Celebrities</font><br> 
<font color="#333333">in last 24 hours</font> 
<br> 
<br> 

<a href="page.php?table=today">Today</a> 
<a href="page.php?table=week">Week</a> 
<a href="page.php?table=month">Month</a> 

<?php 
if (!in_array($table, array('today', 'week', 'month')) { 
    return false; 
} 

global $wpdb; 
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table); 
foreach($result as $row) { 
echo '<a href="http://www.celebrything.com/?s=' . 
    urlencode($row->name) . '&search=Search">' . $row->name . 
    '</a> - ' . $row->count . ' Posts<br/>'; 
} 
} 

?> 

showTable($_GET['table']); 


</h2> 
</div> 

</div> 

<div class="clear"></div> 

更新的代码 ----------------

<div id="sidebar"> 

<div class="post"> 
<h2> 

<font color="#333333">Most Popular Celebrities</font><br> 
<font color="#333333">in last 24 hours</font> 
<br> 
<br> 

<a href="page.php?table=today">Today</a> 
<a href="page.php?table=week">Week</a> 
<a href="page.php?table=month">Month</a> 

<?php 
if (!in_array($table, array('today', 'week', 'month'))) { 
    return false; 
} 

global $wpdb; 
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table); 
foreach($result as $row) { 
echo '<a href="http://www.celebrything.com/?s=' . 
    urlencode($row->name) . '&search=Search">' . $row->name . 
    '</a> - ' . $row->count . ' Posts<br/>'; 
} 



if (!empty($_GET['table'])) { 
showTable($_GET['table']); 

} else { showTable('today'); } 

?> 




</h2> 
</div> 

</div> 

<div class="clear"></div> 

回答

2

1.缺少一个)

if (!in_array($table, array('today', 'week', 'month'))) { 
    return false; 
} 

2.有一个额外的}权befor Ë收盘?>

} 
} 

?> 

您需要关闭?>像以前一样把showTable功能:

showTable($_GET['table']); 
?> 

总结:

获得一个代码编辑器,支持语法高亮。你会喜欢的。

+0

谢谢。现在得到这个错误:解析错误:语法错误,意外'}'在/home/content/c/e/l/celebrything/html/wp-content/themes/celebrything/sidebar.php在线27 我想那里必须成为我组织这一方式的一个问题。是PHP调用和showTable($ _ GET ['table']);在正确的地方? – Mike 2009-12-11 18:22:28

+0

谢谢。现在没有错误,但没有显示结果。我已经使用我正在使用的新代码更新了我的Q.有任何想法吗? – Mike 2009-12-11 18:30:45

+0

你需要改变if(empty to if(!empty – 2009-12-11 18:48:15

2

在我看来,你正在引用一个函数 - showTable() - 但你还没有设置你的逻辑函数内(除非你离开了代码示例)。应该是:

<? 
//---------------------- 
//Create the showTable() function, which won't do anything until it's called. It can 
//reside anywhere on the page, really. It's here just because this is where I put it. 

function showTable($table) { 
    if (!in_array($table, array('today', 'week', 'month'))) { 
     return false; 
    } 

    global $wpdb; 
    $result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table); 
    foreach($result as $row) { 
     echo('<a href="http://www.celebrything.com/?s='.urlencode($row->name) . '&search=Search">'.$row->name.'</a> - '.$row->count.' Posts<br/>'); 
    } 
} 

//---------------------- 
//Here is where you actually call the function, to display some stuff on the page 

if (!empty($_GET['table'])) { 
    showTable($_GET['table']); 
} else { 
    showTable('today'); 
} 
?> 

上面的代码假设你使用内置到WordPress的适当/工作功能(我不知道WordPress的非常好)。但上面的语法应该清除任何函数语法相关的问题,我认为这是您的主要问题。