【发布时间】:2011-02-27 06:34:54
【问题描述】:
这是我的分页脚本:
<?php
/***********************************
* PhpMyCoder Paginator *
* Created By PhpMyCoder *
* 2010 PhpMyCoder *
* ------------------------------- *
* You may use this code as long *
* as this notice stays intact and *
* the proper credit is given to *
* the author. *
***********************************/
?>
<head>
<title> Pagination Test - Created By PhpMyCoder</title>
<style type="text/css">
#nav { font: normal 13px/14px Arial, Helvetica, sans-serif; margin: 2px 0; }
#nav a { background: #EEE; border: 1px solid #DDD; color: #000080; padding: 1px 7px; text-decoration: none; }
#nav strong { background: #000080; border: 1px solid #DDD; color: #FFF; font-weight: normal; padding: 1px 7px; }
#nav span { background: #FFF; border: 1px solid #DDD; color: #999; padding: 1px 7px; }
</style>
</head>
<?php
//Require the file that contains the required classes
include("pmcPagination.php");
//PhpMyCoder Paginator
$paginator = new pmcPagination(20, "page");
//Connect to the database
mysql_connect("localhost","root","PASSWORD");
//Select DB
mysql_select_db("tvguide");
//Select only results for today and future
$result = mysql_query("SELECT programme, channel, airdate, expiration, episode, setreminder FROM epdata1 where airdate >= now() order by expiration GROUP BY airdate");
//You can also add reuslts to paginate here
mysql_data_seek($queryresult,0) ;
while($row = mysql_fetch_array($result))
{
$paginator->add(new paginationData($row['programme'],
$row['channel'],
$row['airdate'],
$row['expiration'],
$row['episode'],
$row['setreminder']));
}
?>
<?php
//Show the paginated results
$paginator->paginate ();
?><? include("pca-footer1.php"); ?>
<?php
//Show the navigation
$paginator->navigation();
?>
但是,我有两个表,它们是 epdata1(我的节目 House M.D. 的播放时间所在的位置)和 housemdep 加上 setreminder 表。
我如何使用与此相关的外键?我不确定这是否适用于我的脚本,但我愿意尝试。
我想做的是从表 housemdep 中选择某些剧集 (节目的剧集),如果有任何被选中,它会显示如下:
House M.D. showing on Channel 1 June 6th - 8:00pm "Wilson" Set Reminder
House M.D. showing on Channel 1 June 7th - 1:30am "Wilson" Set Reminder
House M.D. showing on Channel 1 June 7th - 12:55pm "House's Head" Set Reminder
或者像这样,如果我没有从该行中选择一集:
House M.D. showing on Channel 1 June 7th - 8:00pm "House's Head" Set Reminder
House M.D. showing on Channel 1 June 8th - 9:00pm Set Reminder
House M.D. showing on Channel 1 June 9th - 2:30pm Set Reminder
House M.D. showing on Channel 1 June 7th - 8:00pm "Que Sera Sera" Set Reminder
外键和互连表的关系对我来说是新的,如果有人可以提供帮助,我将不胜感激。
另外,我正在尝试为我的程序获得这样的效果(如果您在浏览器中单击“查看源代码”,这就是代码应该呈现的方式):
<tr><td><b><a href="housemd.php">House M.D.</a></b></td><td>showing on <a href="channel/1"><i>Channel 1</i></a></td><td>June 9th - 7:00pm</td><td><b>"<a href="episodes/714790">House's Head</a>"</b></td><td><img src="reminder.gif" height="16" width="22"> <a href="reminder.php" alt="Set a reminder" target="_top">Set Reminder</a></td></tr>
House M.D.在 Channel 16 月 10 日 - 12:25am“House's Head” 放映设置提醒 House M.D.在 Channel 16 月 10 日 - 下午 12:55 放映设置提醒 House M.D.在 Channel 16 月 10 日 - 晚上 9:00“Wilson” 放映设置提醒 House M.D.在第 1 频道6 月 11 日 - 凌晨 1:30“Wilson” 放映设置提醒 House M.D.在 Channel 16 月 11 日 - 晚上 8:00“活出梦想” 放映设置提醒 House M.D.在 第 1 频道6 月 12 日 - 晚上 7:00 放映设置提醒
我已经在这个脚本的另一个版本中尝试了谷歌关于外键的一些建议(这是在我的 localhost 服务器上运行 Apache 和 PHP 5.28/MySQL 的原始克隆),但我不确定如何实现这个.
谢谢。
【问题讨论】:
-
您遇到了什么问题?您在通过外键将表连接在一起的数据库查询方面需要帮助吗?如果没有,那么将表格连接在一起,看看你的分页做了什么。最好的学习方法是尝试。进行更改以修复。此外,这并不是对查询进行分页的最佳方式。如果您的查询有 10k 个结果,它将缓冲所有这些结果,然后您只使用 10k 缓冲列表中的 20 个(或任何您的每页值)。通常最好使用 mysql 关键字 LIMIT 让您的查询只返回所需的行数。
-
我在使用通过外键将表连接在一起的数据库查询时遇到问题,这就是它的要点。至于每个脚本显示 20 行的分页脚本,它是我正在使用的免费脚本;)
标签: php sql primary-key