【发布时间】:2009-12-11 16:54:47
【问题描述】:
不确定这是否是表达我正在尝试做的事情的最佳方式。如下:
我希望用户能够根据三个不同的表从我的数据库中显示结果,一次一个。
我已准备好查询,但只想根据用户点击的内容一次在页面上显示一个结果。查询基于 3 个不同的表。有今日表、本周表和本月表。
因此,当用户单击“今天”时,我想显示“今天”表中的结果。当他们单击本周时,我希望结果切换为来自本周表。我假设这可以通过 PHP 中的简单 if-then 逻辑来完成。
这是我从 Today 表中调用的方式:
<?php
global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_today');
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
urlencode($row->name) . '&search=Search">' . $row->name .
'</a> - ' . $row->count . ' Posts<br/>';}
?>
我会像这样从本周表中调用:
<?php
global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_thisweek');
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
urlencode($row->name) . '&search=Search">' . $row->name .
'</a> - ' . $row->count . ' Posts<br/>';}
?>
此查询当前正在从页面加载运行。如何插入逻辑以使其通过单击“今天”、“本周”或“本月”运行?
好的 - 感谢您到目前为止的帮助!我有这个:
<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>
我收到此错误:
解析错误:语法错误,第 16 行 /home/content/c/e/l/celebrything/html/wp-content/themes/celebrything/sidebar.php 中出现意外的“{”
【问题讨论】:
-
不确定我的
-
我编辑了我的答案。这有帮助吗?